代码之家  ›  专栏  ›  技术社区  ›  Cheok Yan Cheng

importTerror:无法导入名称tz(psycopg2)

  •  0
  • Cheok Yan Cheng  · 技术社区  · 15 年前

    我使用的是Windows XP,使用的是Python运行时 http://www.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
    

    这是python脚本。

    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

    1 回复  |  直到 15 年前
        1
  •  1
  •   Evan Fosmark    15 年前

    我猜Python不知道你的egg缓存位置(或者没有权限)。你只需要设定一下。更多信息 here . 尝试设置 WSGIPythonEggs 指令。