2017-09-26 66 views
0

我正在玩Flask/Python RESTful API,一切都很好,直到我开始尝试学习如何提供它。当然,我在本地尝试了这一点。Python 3.6 Flask与Windows上的mod_wsgi:没有名为队列的模块

我安装了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'

我已经冲刷的interwebs和已阅读关于“队列”与“队列”,但我不直接导入它。

这是我目前的代码。

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

你的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库。

+0

这是很容易做到的事情吗?我从来没有这样做过。我是python的新手。 – gin93r

+0

另外,AMPPS会带有python 3,并有2.7版本的mod_wsgi,这似乎很奇怪。 – gin93r

+0

考虑通过使用mod_wsgi-express在命令行上运行WSGI服务器开始。这样你就不需要触摸系统的Ap​​ache配置。请参阅https://pypi.python.org/pypi/mod_wsgi和http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html –

相关问题