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?


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

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .