Hi, will you please advise me on how to correctly activate virtualenv via wsgi file using Python 3.4. I still receive ImportError when loading django module which makes me believe that virtualenv is not properly activated. I followed this thread but without any success: https://community.webfaction.com/questions/10804/using-virtualenvs-with-django It should be something like this but for python 3.4:
This is how my wsgi file looks like:
Thanks, Jakub asked 22 Dec '15, 17:35 jakub_l |
Contrary to what you will see in many examples on the web, you do not need to do anything in your WSGI handler to activate your virtualenv. The correct way to activate your virtualenv is explained by the author of mod_wsgi in his blog: Using Python virtual environments with mod_wsgi In short, all you need to do is add a
(That should all be on a single line.) answered 22 Dec '15, 20:15 seanf Thanks, Sean. It looks pretty streightforward but although I tried almost every possible path, it still raises the ImportError for django module. I also included path to "site-packages" directory as advised by the blog post. This is the part of my httpd.conf: WSGIDaemonProcess app_name processes=2 threads=12 python-home=/home/username/webapps/app_name/env python-path=/home/username/webapps/app_name/project_name:/home/username/webapps/app_name/env/lib/python3.4/site-packages
(23 Dec '15, 08:40)
jakub_l
You do not need to include the site-packages directory in the python-path parameter. What's the exact error that you're seeing?
(23 Dec '15, 13:37)
seanf
Well, it turned out to be a "Target WSGI script cannot be loaded as Python module" error. Is that right that python-home targets a root of my virtualenv dir and python-path a dir where manage.py lies? Thanks
(23 Dec '15, 23:26)
jakub_l
Yes.
Yes, and you can include any other paths that contain Python modules that aren't in your virtualenv. If you post the entire traceback that came with that error message, we can probably help you further.
(23 Dec '15, 23:51)
seanf
Thank you, Sean! Eventually, this worked for me: WSGIDaemonProcess appname processes=2 threads=12 python-home=/home/username/webapps/appname/env python-path=/home/username/webapps/appname/env/lib/python3.4:/home/username/webapps/appname/path/to/dir/with/managepy. So, your solution was perfectly right... the last part (path to manage.py) was necessary because of my project structure (manage.py is not in the root of my project folder)
(27 Dec '15, 12:50)
jakub_l
|