[Answer]-Installing Django with mod_wsgi in centos, ImportError: No module named os

1👍

Run ‘ldd’ on the mod_wsgi.so.

The problem is likely that it is finding a different Python version. It can also be that since your Python is not in a standard location, that it doesn’t know where to find the installation.

In the latter case, add at global scope, outside of VirtualHost, in your Apache configuration:

WSGIPythonHome /root/epd-5.1.0

The value should correspond to the value of sys.prefix printed from your Python when run.

import sys
print sys.prefix

0👍

Based on the errors you’ve got, it seems like a couple of things could be going on. Rather than throwing all this into comments, however, I’ll go ahead and post as an answer.

In my django.wsgi file I have the following two lines that change the PATH environment variable to let python import packages from my django project:

import sys
sys.path.append('/path/to/mysite.com/app/mydjangoproject')

You’ll also want to make sure you add the following in your httpd.conf inside the VirtualHost that will you will be using django with:

<Directory /path/to/mysite.com/app/mydjangoproject>
    Order allow,deny
    Allow from all
</Directory>

EDIT:

With regard to the symbolic link that you mention in your comments that appears in the error messages, I’m not quite sure what to make of it. If you are just trying to use it to allow apache to access resources that are outside of the DocumentRoot, you’ll want to add the Options FollowSymLinks directive for Directory that contains the symbolic link

Leave a comment