views:

89

answers:

2

Hi, I'm writing a bare bones Python wsgi application and am getting stumped by module import errors. I have a .py file in the current directory which initially failed to import. By adding

sys.path.insert(0, '/Users/guhar/Sites/acom')

the import of the module worked. But I now try and import a module that I had installed via easy_install and it fails to import. I tried setting

sys.path.insert(0, '/Library/Python/2.5/site-packages/')

which contains the egg file, but to no avail. I would've thought that all packages under "/Library/Python/2.5/site-packages/" would be available to a WSGI application.

Does anybody have any pointers?

+2  A: 

Read:

http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

You cant simply add Python module directories containing .pth files into sys.path. You must use site.addsitedir() or use other options of mod_wsgi to have it use the virtual environment.

I think though perhaps, given that it looks like you are using MacOS X, that you have installed a second installation of Python and whatever mod_wsgi is using is not the version you have installed your packages into. That or your second Python installation is broken which often can be the case on MacOS X.

BTW, I am assuming that when you say WSGI you actually mean mod_wsgi given the tag you used. If you do, please do not use WSGI to refer to mod_wsgi. WSGI is a specification only, mod_wsgi is a specific hosting implementation. You should not be using the terms interchangeably.

Graham Dumpleton
A: 

If you're running under Apache mod_wsgi, specify all necessary python paths in your virtual host configuration like this:

WSGIDaemonProcess ... python-path=/srv/lala/www:/srv/lala/lib/python2.6/site-packages:/Library/Python/2.5/site-packages
nailxx