openshift / origin-server

OpenShift 2 (deprecated)
889 stars 516 forks source link

Python 3 does not have proper virtualenv #6307

Closed avinassh closed 8 years ago

avinassh commented 8 years ago

(I am no using Openshift on personal server, but this about openshift.com)

Whenever I create a new app with Python 3, the virtualenv does not have activate_this.py file. Usually it is located at

/var/lib/openshift/<app_id>/python/virtenv/bin/activate_this.py

Even docs also suggest same path, however there is no such file created. Infact, bin directory is not even present. Its actual location is

/var/lib/openshift/<app_id>/python/virtenv/venv/bin

bin should contain activate_this.py, but it does not have it.

To reproduce, create a new app with Python 3.3:

rhc create-app app-name python-3.3

ssh into app and look in python directory.

dinhxuanvu commented 8 years ago

@avinassh Hi, since version 3.3, Python library includes venv module which you can use instead of virtualenv. So, virtualenv is no longer installed with Python 3.3 anymore. You can use pyvenv command to use venv module. The functionality should be similar. If you still insist on using virtualenv, then you can create an app with Python 2.7. I hope this helps.

avinassh commented 8 years ago

Can you also tell me how to activate the virtualenv in Openshift?

dinhxuanvu commented 8 years ago

@avinassh If you have Python 3.3 app on OpenShift then there is no virtualenv to activate. You can use pyenv like I mentioned on previous email. I embedded a link to the document so you can take a look and figure out how to use it properly. If you have a Python 2.7 app, then the activate_this.py file should be located in python/virtenv/bin/ after you ssh to the app.

avinassh commented 8 years ago

I didn't get you. Are you saying in Python 3, virtualenv is pre activated?

and also I don't understand how can I use pyenv in Openshift

dinhxuanvu commented 8 years ago

@avinassh Like I said above, there is no virtualenv in Python 3.3 app on OpenShift. If you want to use pyvenv, please take a look at the link I embedded on the first comment. If you look at the first couple lines on the document, it shows you the command pyvenv /path/to/new/virtual/environment to create the directory for your virtual environment where you can install your packages or dependencies. Also, you can take a look at this document as it shows more examples that you can try out. Also, again, if you are more comfortable with virtualenv, then you should use Python 2.7 app on OpenShift instead as it still has virtualenv. I have not used pyvenv before so I won't be able to offer more expertise than I already did. Don't worry about breaking the app. You can always delete and re-create it with OpenShift :).

avinassh commented 8 years ago

@dinhxuanvu thanks for replying. I don't mind using pyvenv and I have used it earlier plenty of times. I don't mind using virtualenv either. In my earlier message I made a mistake, I should have asked about how to activate pyvenv. I am sorry for the confusion there. I know I can activate with bash command pyvenv /path/to/new/virtual/environment, but I can't seem to figure out how to do this in Openshift. The pyvenv has to be activated before anything else and it should happen from wsgi.py file in Openshift. I have tried running pyvenv /path/to/new/virtual/environment within os.system or using subprocess, but it is not working. Thats why I wanted to know how do I activate pyvenv in Openshift. With Python 2 I can use execfile to execute activate_this.py within wsgi, but with Python 3 and pyvenv I am not able to figure out. Hope I am clear here.

dinhxuanvu commented 8 years ago

@avinassh Just to be clear here. Are you talking about pyvenv or pyenv (note there is an extra "v" between "py" and "env")? pyenv is a version control for Python which is pretty much equivalent of rvm/rbenv in Ruby but pyvenv is virtual environment tool. They are certainly not the same thing.

avinassh commented 8 years ago

pyvenv.. missed a v at some places

dinhxuanvu commented 8 years ago

@avinassh If you are working within your git repo then the pyvenv is not there as it's only installed on the app/gears. You can try to ssh to the app rhc ssh and then use source python/virtenv/venv/bin/activate. It should activate venv module for you to use. Also, you can explore that directory to see if something can be helpful for you as well. Give it a try to see if it helps.

avinassh commented 8 years ago

^no, that approach is wrong. I have to do that everytime when I create a new app or restart the app. It shouldn't be done manually like that in a deployment server.

dinhxuanvu commented 8 years ago

@avinassh I can't simply help you out with every single Python package/tool out there for your project as many of those I haven't used myself before. You certainly need to do some researches on how to use them and perhaps do some trials/tests on OpenShift to see how they work. Here are couple links that are posted on either GitHub or OpenShift blog: Link-1, Link-2, Link-3, Link-4, Link-5. On those posts, they either used virtualenv or pyvenv so you can somewhat learn from their approaches. However, be aware that some of posts used different OS such as Ubuntu so their commands may be different with what you should do on your Fedora/RHEL/Centos system. If you still can't find a solution for your project after reading those posts, I recommend you to post your question on stackoverflow.com and tag 'openshift' + 'python' + 'virtualenv' + 'pyvenv'. There may be someone else out there who may have some experiences on virtual environment on OpenShift that may be able to help you further.

dinhxuanvu commented 8 years ago

Hi, I haven't heard from you for a while. I assume that you have resolved your issue. This issue will be closed soon. Thanks! @abhgupta Would you mind closing this issue? Thanks.

avinassh commented 8 years ago

@dinhxuanvu sorry I forgot to reply. yes, I had to roll down my own solution.

btw none of the links you gave earlier work and still the official document is misleading.

and also, Openshift does not provide any proper way to do this and rolling down own version to activate virtualenv is a terrible idea.

dinhxuanvu commented 8 years ago

@avinassh Sorry I can't be a bigger help for you. If you feel some documents online are still misleading, please submit a request on openshift/devcenter repo to let them know your findings. They may be able to fix the documents to avoid the confusion in the future. Also, if you have a solution for pyvenv on Python 3.3 cartridge, please by all mean sharing with the devcenter team. We would certainly appreciate that.

avinassh commented 8 years ago

Sure! Give me sometime.