在Windows上使用mod_wsgi的Python 3.6 Flask:没有名为queue

时间:2017-09-26 22:40:19

标签: python flask mod-wsgi

我正在使用Flask / Python RESTful api,一切顺利,直到我开始尝试学习如何服务它。当然我在当地尝试了这个。

我安装了AMPPS,因为它默认安装并启用了python和mod_wsgi。我经历了所有的设置,我得到了默认的“Hello World!”申请工作。好哇!正确?

然后我尝试开始引入我的应用程序,这就是我遇到障碍的地方。

起初,我收到的错误是没有名为flask的模块。经过一些阅读后,我了解到我需要像这样加载我的virtualenv:

activate_this = 'path/to/venv/Scripts/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

这似乎适用于烧瓶,但后来我得到了:

ModuleNotFoundError: No module named 'queue'

我已经搜索了互联网并阅读了“队列”与“队列”,但我没有直接导入它。

这是我目前的代码。

activate_this = 'path/to/venv/Scripts/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

# this line is what causes the error
from flask import Flask

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'
    response_headers = [('Content-type', 'text/plain'),('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

你的mod_wsgi实际上是为Python 2.7编译的,而不是3.6。该错误是因为Queue模块在​​3.6中已重命名为queue,因此当在2.7下导入queue时,它将失败。

您需要卸载mod_wsgi并安装为Python 3.6编译的版本。您不能强制为一个Python版本编译的mod_wsgi版本通过将其指向不同版本的Python虚拟环境而作为不同版本运行。这是因为mod_wsgi直接链接到特定版本的Python库。