1)我尝试设置一个新的Web环境来托管python + psycopg2代码。下面是我的步骤:问题安装并运行psycopg2 + Windows + Apache2 + mod_wsgi
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软件基金会\ APACHE2.2 \模块, 并将其重命名作为mod_wsgi.so
新增以下行到C:\ Program Files文件\ Apache软件基金会\ 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软件基金会\ 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]
我会得到
导入错误:没有模块名为psycopg2
我怎么能告诉Apache,我曾在C:上安装了psycopg2模块:\ Python26
8 )我运行以下独立脚本来显示已安装psycopg2。
import psycopg2
print "Hello, World!"
我把它用
C:\Documents and Settings\yan-cheng.cheok\Desktop>mypython.py
Hello, World!
似乎我的Python环境中正常运行。
映射到一个目录上它在WSGIScriptAlias安装URL尾部斜杠线是重要的,当这应该有问题,以及。 – 2010-01-30 02:52:18