被WSGI模块导入错误所困扰 [英] stumped by WSGI module import errors

查看:83
本文介绍了被WSGI模块导入错误所困扰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的Python wsgi应用程序,并且被模块导入错误所困扰.我在当前目录中有一个.py文件,该文件最初无法导入.通过添加

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')

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

模块导入成功.但是我现在尝试导入通过easy_install安装的模块,但是导入失败.我尝试设置

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/')

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

包含egg文件,但无济于事.我本以为WSGI应用程序可以使用"/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.

有人有指针吗?

推荐答案

阅读:

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

您不能简单地将包含.pth文件的Python模块目录添加到sys.path中.您必须使用site.addsitedir()或使用mod_wsgi的其他选项才能使其使用虚拟环境.

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.

尽管如此,我认为,也许您似乎正在使用MacOS X,但是您已经安装了第二次安装的Python,而使用的mod_wsgi并不是您将软件包安装到的版本.那或您的第二个Python安装被破坏了,这在MacOS X上通常是这种情况.

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.

顺便说一句,我假设当您说WSGI时,实际上是指给定您使用的标记的mod_wsgi.如果这样做,请不要使用WSGI来引用mod_wsgi. WSGI仅是一个规范,mod_wsgi是一个特定的托管实现.您不应该互换使用这些术语.

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.

这篇关于被WSGI模块导入错误所困扰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆