导入错误:无法导入名称 tz (psycopg2)
我使用的是 Windows XP,并使用 http://www 中的 Python 运行时.python.org/ftp/python/2.7/python-2.7.msi
如果我在独立应用程序中运行,import psycopg2
不会给我带来任何麻烦。但是,当来到 mod_wsgi + apache 时,我会收到以下错误
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi (pid=2832): Target WSGI script 'C:/Projects/SandBox/web/script/index.py' cannot be loaded as Python module.
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi (pid=2832): Exception occurred processing WSGI script 'C:/Projects/SandBox/web/script/index.py'.
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "C:/Projects/SandBox/web/script/index.py", line 9, in <module>
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] import psycopg2
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "build\\bdist.win32\\egg\\psycopg2\\__init__.py", line 65, in <module>
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] from psycopg2 import tz
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] ImportError: cannot import name tz
Here is the python script。
import sys, os
sys.path.append(os.path.dirname(__file__))
import psycopg2
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]
这是 httpd.conf 文件。
LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
WSGIScriptAlias / "C:/Projects/SandBox/web/"
<Directory "C:/Projects/SandBox/web">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
我检查存档C:\Python27\Lib\site-packages\psycopg2-2.2.2-py2.7-win32.egg\
,有C:\Python27\Lib\site -packages\psycopg2-2.2.2-py2.7-win32.egg\psycopg2\tz.py
I am using Windows XP, and using Python run time from http://www.python.org/ftp/python/2.7/python-2.7.msi
If I am running in standalone application, import psycopg2
doesn't cause me any trouble. However, when come to mod_wsgi + apache, I will get the following error
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi (pid=2832): Target WSGI script 'C:/Projects/SandBox/web/script/index.py' cannot be loaded as Python module.
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi (pid=2832): Exception occurred processing WSGI script 'C:/Projects/SandBox/web/script/index.py'.
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "C:/Projects/SandBox/web/script/index.py", line 9, in <module>
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] import psycopg2
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "build\\bdist.win32\\egg\\psycopg2\\__init__.py", line 65, in <module>
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] from psycopg2 import tz
[Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] ImportError: cannot import name tz
Here is the python script.
import sys, os
sys.path.append(os.path.dirname(__file__))
import psycopg2
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]
and here is the httpd.conf file.
LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
WSGIScriptAlias / "C:/Projects/SandBox/web/"
<Directory "C:/Projects/SandBox/web">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
I check the archive C:\Python27\Lib\site-packages\psycopg2-2.2.2-py2.7-win32.egg\
, there is C:\Python27\Lib\site-packages\psycopg2-2.2.2-py2.7-win32.egg\psycopg2\tz.py
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是Python不知道你的egg缓存位置(或者没有权限)。你只需要设置它。更多信息此处 。尝试设置
WSGIPythonEggs
指令。My guess would be that Python doesn't know your egg cache location (or doesn't have privileges to it). You just need to set that. More information here. Try setting the
WSGIPythonEggs
directive.