LaVOZs

The World’s Largest Online Community for Developers

'; python - stumped by WSGI module import errors - LavOzs.Com

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?

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.

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
Related
Calling a function of a module by using its name (a string)
How to import a module given the full path?
Import a module from a relative path
How to import a module given its name as string?
Importing files from different folder
mod_wsgi: import python modules with the same name
WSGI - importing user made classes
Relative imports for the billionth time
WSGI cannot import locally installed packages
What does from __future__ import absolute_import actually do?