On Tue, Jun 5, 2012 at 9:53 AM, ivanb <[email protected]> wrote: > I'm putting my django site in production for the first time so please > forgive for my ignorance. > > I'm trying to put my django site on apache. I've read documentation > about mod_wsgi and tried that simple Hello world so it is configured > OK. The problem I'm having seems to be with using virtualenvs with it. > I wanna set things up properly including virtualenvs and everything so > I'm ready for future sites. > > To the problem now. > > The error I'm getting in apache log is: > > No module named django.core.handlers.wsgi > > So it seems that it is not reading my virtualenvs properly. > > This is my wsgi script: > import os > import sys > import site > site.addsitedir('/home/user/.virtualenvs/myapp/lib/python2.7/site- > packages') > > path = '/home/user/django/myapp/myapp' > if path not in sys.path: > sys.path.append(path) > > sys.stdout = sys.stderr > print sys.path > > os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' > > import django.core.handlers.wsgi > application = django.core.handlers.wsgi.WSGIHandler() > > And this is the error log from apache. I printed out the sys.path so > you can see what it looks like. > > [Tue Jun 05 14:54:07 2012] [error] ['/usr/lib/python27.zip', '/usr/ > lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/ > lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib- > dynload', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site- > packages/PIL', '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg- > info', '/home/user/.virtualenvs/myapp/lib/python2.7/site-packages', '/ > home/user/django/myapp/myapp'] > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi > (pid=1039): Target WSGI script '/srv/http/wsgi_scripts/myapp.wsgi' > cannot be loaded as Python module. > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi > (pid=1039): Exception occurred processing WSGI script '/srv/http/ > wsgi_scripts/myapp.wsgi'. > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] Traceback > (most recent call last): > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] File "/srv/ > http/wsgi_scripts/myapp.wsgi", line 17, in <module> > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] import > django.core.handlers.wsgi > [Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] ImportError: > No module named django.core.handlers.wsgi > > If you have any suggestions or already had similar issue please help. > > Thanks
You have a few choices: 1. You can do hand crafted path manipulations in you .wsgi file to make the path look right, or at least make the stuff that you need come first. The wrong site.py will already have been imported, so you either need to replicate the effect of any .pth files in your virtualenv, or call the appropriate function from site.py on the directory, but you will have to be careful to be sure these get put before any corresponding items you've left in sys.path from the initial import of site.py. 2. You can use the Apache configuration directive WSGIPythonHome, pointing it to your virtual env (the directory containing lib and bin). Note that this only works for one virtualenv because it is a global setting. 3. If you need to run more than one virtualenv on an Apache (rather than multiple Apache's behind a front end virtual hosting proxy), you can snag a recent modwsgi 4.0 trunk checkout (I don't know if this has been released and/or backported to 3.x), which supports the "python-home" option to the WSGIDaemonProcess directive, in which case the PYTHONHOME environment variable can be set differently for different daemon process groups, and different vhosts can use different daemon process groups. There are other restrictions on options you can select with this, but the default configuration is fine. I'm using the third scheme on a test box, and it works fine for me. Bill 2. You can -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
