基于python的网络应用程序的新功能,所以我有些迷茫。这是我的apache错误:
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Target WSGI script '/home/http/public/hello/hello.wsgi' cannot be loaded as Python module.
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Exception occurred processing WSGI script '/home/http/public/hello/hello.wsgi'.
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] Traceback (most recent call last):
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File "/home/http/public/hello/hello.wsgi", line 3, in <module>
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] from hello import app as application
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File "/home/http/public/hello/hello.py", line 1, in <module>
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] from flask import Flask
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] ImportError: No module named 'flask'
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File does not exist: /home/http/public/favicon.ico
显然,它无法找到flask
模块。我看了这个,似乎大多数人通过将项目目录附加到路径来使其工作,如下所示:(hello.wsgi)
import sys
sys.path.insert(0, "/home/http/public/hello")
from hello import app as application
这是hello.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='0.0.0.0')
在以python hello.py
运行时效果很好但是,在浏览到主机/ hello时会抛出500错误。这是Apache配置:
WSGIDaemonProcess hello user=http group=http threads=5
WSGIScriptAlias /hello "/home/http/public/hello/hello.wsgi"
<Directory /home/http/public/hello/>
WSGIProcessGroup hello
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
我有点失落。
答案 0 :(得分:3)
mod_wsgi模块是针对特定的Python版本构建的,只能与该版本一起使用。您不能强制它使用其他版本。因此,如果您安装了多个版本,则需要确保安装软件包并在开发中针对相同版本运行代码。
您可以通过运行测试来确定mod_wsgi正在使用哪个Python版本/安装: