【发布时间】: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
访问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