Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm setting up Apache2 and mod_wsgi for Django in Debian, but I found problems. First, these are my directories:

/webapps/lib/python2.6/site-packages # python eggs
/webapps/lib/python2.6/ # python libraries
/webapps/myproject.wsgi # wsgi script
/webapps/myproject/ # django project

And this is the directory /webapps/lib/python2.6 (permissions are 777):

├── django
│   ├── bin
│   ├── conf
│   ├── ...
│   └── views
└── site-packages
    ├── easy-install.pth
    ├── mongoengine-0.5.3-py2.6.egg
    ├── pymongo-2.1-py2.6-linux-x86_64.egg
    └── site.py

In httpd.conf I have this:

WSGIScriptAlias / /webapps/myproject.wsgi
WSGIPythonEggs /webapps/lib/python2.6/site-packages/

And finally in myproject.wsgi:

import sys
sys.path.insert(0, '/webapps/lib/python2.6/site-packages')
sys.path.insert(0, '/webapps/lib/python2.6')
sys.path.insert(0, '/webapps/myproject')

.. Nothing important

# I tried 2 lines above as well, but nothing
#import os
#os.environ["PYTHON_EGG_CACHE"] = "/webapps/lib/python2.6/site-packages"

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

# This for trying if system reads eggs
    import mongoengine
except Exception as e:
    raise ImportError(str(e) + ". " + str(sys.path))

When I restart Apache and try to visit any webpage, I get error 500 and this in the log:

[Wed Jan 04 18:18:12 2012] [error] [client] ImportError: No module named mongoengine. ['/webapps/myproject', '/webapps/lib/python2.6', '/webapps/lib/python2.6/site-packages', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6']

So as you can see django is imported well, but none of the eggs are imported. However I didn't find any other way to import them. Why eggs are not imported?


share|improve this question
Where is the mongoengine module located? –  Shane Madden Jan 4 '12 at 19:29
mongoengine is located in site-packages, as you can see in the file diagram. –  Menda Jan 4 '12 at 21:03
Ah, missed that. Have you tried extracting the eggs and see if the package directories themselves will load? –  Shane Madden Jan 4 '12 at 21:21
Yes. By the way, I just found the solution.. after 3 hours :\ Thanks! –  Menda Jan 4 '12 at 21:29
Ahh, nice - glad you got it fixed! –  Shane Madden Jan 4 '12 at 21:39

1 Answer 1

up vote 1 down vote accepted

I just found the solution. Everything was perfect, and even though I was restarting Apache it was throwing all the time the same error. As there are many processes of Apache running, the key was doing a killall httpd and then starting the service again. Some kind of cache or process was alive with wrong data so it wasn't working properly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.