Python 问题:安装并运行psycopg2+;Windows+;Apache2&x2B;mod_wsgi
1) 我尝试设置一个新的web环境来承载python+psycopg2代码。以下是我的步骤: 2) 下载 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 4) 使用以下内容保存名为C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wsgi\myapp.py的文件:Python 问题:安装并运行psycopg2+;Windows+;Apache2&x2B;mod_wsgi,python,Python,1) 我尝试设置一个新的web环境来承载python+psycopg2代码。以下是我的步骤: 2) 下载 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
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) 使用
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /wsgi/ "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wsgi/"
6) 安装
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:\Python26中安装了psycopg2模块
8) 我运行以下独立脚本以显示已安装psycopg2
import psycopg2
print "Hello, World!"
我使用
C:\Documents and Settings\yan-cheng.cheok\Desktop>mypython.py
Hello, World!
看来我的python环境还不错。我可以通过将python脚本移到htdocs之外来解决这个问题
WSGIScriptAlias /wsgi "C:/wsgi/"
<Directory "C:/wsgi">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias/wsgi“C:/wsgi/”
不允许超限
选项无
命令拒绝,允许
通融
通过将python脚本移到htdocs之外,我能够解决这个问题
WSGIScriptAlias /wsgi "C:/wsgi/"
<Directory "C:/wsgi">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias/wsgi“C:/wsgi/”
不允许超限
选项无
命令拒绝,允许
通融
这应该有问题,当映射到一个目录时,挂载在WSGIScriptAlias行中的URL尾随斜杠很重要。这应该有问题,当映射到一个目录时,挂载在WSGIScriptAlias行中的URL尾随斜杠很重要。