2

对基于 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,但是在浏览到 host/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>

我有些失落。

4

1 回答 1

3

mod_wsgi 模块是针对特定的 Python 版本构建的,并且只能与该版本一起使用。您不能强制它使用不同的版本。因此,如果您安装了多个版本,则需要确保您正在安装软件包并在开发中针对同一版本运行代码。

您可以通过运行测试确定使用哪个 Python 版本/安装 mod_wsgi:

于 2013-05-08T23:38:49.033 回答