stumped by WSGI module import errors

谁说我不能喝 提交于 2019-12-12 18:08:22

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/2917972/stumped-by-wsgi-module-import-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!