【发布时间】:2010-11-12 07:48:03
【问题描述】:
我正在使用 Apache + mod-wsgi。
在我的 httpd.conf 中,文件末尾有以下附加行。
LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
WSGIScriptAlias / "C:/Projects/Folder/web/"
<Directory "C:/Projects/Folder/web">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
当我通过http://localhost/script/index.py在Windows中执行以下index.py脚本时
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
效果很好。
但是,当我在index.py 的第一行添加import utils 时,我得到了
ImportError: No module named utils
utils.py 与index.py 是同一目录
我需要设置什么额外的配置吗?
我尝试了@dan_waterworth 给出的建议
import sys, os
sys.path.append(os.path.dirname(__file__))
通过导入我自己的模块,我不再出现错误。但是,当我通过 easy_install 导入正在安装的模块时,会发生错误。
File "C:/Projects/Folder/web/script\\connection.py", line 1, in <module>
import psycopg2
File "build\\bdist.win32\\egg\\psycopg2\\__init__.py", line 65, in <module>
from psycopg2 import tz
ImportError: cannot import name tz
import psycopg2 执行没有问题,如果此脚本作为独立应用程序执行。
【问题讨论】: