导入错误:无法导入名称 tz (psycopg2)

发布于 2024-10-03 02:11:21 字数 2126 浏览 3 评论 0原文

我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2024-10-10 02:11:21

我的猜测是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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文