3

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

2 Answers 2

3

You haven't added your actual virtualenv site-packages directory to the mix. Try:

import site
site.addsitedir('/path/to/your/virtualenv/lib/python2.X/site-packages')
# Where `X` is the specific version
Sign up to request clarification or add additional context in comments.

1 Comment

Actually I did, I just formatted the question wrong so it's shown as a regular sentence, I'll change it, sorry
2

For anyone that might have similar problem as I did. You need to check the whole path privileges to the directory where your virtualenv is stored.

I checked the home directory and changed privileges, but forgot to change privileges to my user directory and that fixed the thing.

Hope this helps.

1 Comment

What privileges did you use? 775 for all directories?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.