【问题标题】:Problem Install and Run psycopg2 + Windows + Apache2 + mod_wsgi问题安装和运行 psycopg2 + Windows + Apache2 + mod_wsgi
【发布时间】:2010-01-29 06:19:46
【问题描述】:

1) 我尝试设置一个新的 Web 环境来托管 python + psycopg2 代码。这是我的步骤:

2) 下载http://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py26-3.0.so

3) 将 mod_wsgi-win32-ap22py26-3.0.so 复制到 C:\Program Files\Apache Software Foundation\Apache2.2\modules, 并将其重命名为 mod_wsgi.so

将以下新行添加到 C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /wsgi/ "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wsgi/"

4) 保存一个名为 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wsgi\myapp.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]

5) 使用 http://localhost/wsgi/myapp.py

访问

6) 安装http://www.stickpeople.com/projects/python/win-psycopg/psycopg2-2.0.13.win32-py2.6-pg8.4.1-release.exe

7) 如果我将文件内容修改为

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]

我会得到

ImportError:没有名为 psycopg2 的模块

我如何告诉 apache,我已经在 C:\Python26 中安装了 psycopg2 模块

8) 我运行以下独立脚本来显示 psycopg2 已安装。

import psycopg2

print "Hello, World!"

我使用它运行它

C:\Documents and Settings\yan-cheng.cheok\Desktop>mypython.py
Hello, World!

看来我的python环境还可以。

【问题讨论】:

    标签: python


    【解决方案1】:

    我可以通过将 python 脚本移到 htdocs 之外来解决这个问题

    WSGIScriptAlias /wsgi "C:/wsgi/"
    
    <Directory "C:/wsgi">
        AllowOverride None
        Options None
        Order deny,allow
        Allow from all
    </Directory>
    

    【讨论】:

    • 这应该有问题,以及在映射到目录时,它在 WSGIScriptAlias 行中挂载的 URL 上的尾部斜杠很重要。
    猜你喜欢
    • 1970-01-01
    • 2020-09-16
    • 2014-07-04
    • 2011-07-29
    • 1970-01-01
    • 2017-12-14
    • 2018-02-02
    • 2014-02-12
    • 2012-06-22
    相关资源
    最近更新 更多