[Django]-How do I properly setup my python paths and permissions for Django+mod_wsgi deployment?

2👍

Since I’m on Debian it appears that django is in /usr/lib/pymodules/python2.5 and not /usr/lib/python2.5/site-packages.

I added

sys.path.append('/usr/lib/pymodules/python2.5') 

to the top of my wsgi file and that did it, although I feel as though I should be fixing this in a more proper manner.

1👍

I don’t think your problem lies with the sys.path. I’ve always used Mod_WSGI with Django using the Daemonized process, like so,

# Note these 2 lines
WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
WSGIProcessGroup site-1

Alias /media/ /usr/local/django/mysite/media/

<Directory /usr/local/django/mysite/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi

<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all

If you note the first 2 lines – you can specify the group and the user which will be running this. In your case, you mention that www-data can import the django module but it doesn’t work when Apache deploys it – perhaps the process is being run by nobody, or some other user/group that does not have privileges to import this module. Adding the DaemonProcess and Group lines should solve your problem.

HTH.

[1] For reference – here’s the Django Mod_WSGI doc – http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

👤viksit

0👍

Sounds like you mod_wsgi is not compiled against Python 2.5 and instead compiled against Python 2.4 or 2.6. Run:

ldd mod_wsgi.so

on the mod_wsgi.so file where it is installed to work out what it is using.

If it is different, you will need to recompile mod_wsgi from source code such that it uses the version you want to use.

Leave a comment