我正在玩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]
任何帮助,将不胜感激。
这是很容易做到的事情吗?我从来没有这样做过。我是python的新手。 – gin93r
另外,AMPPS会带有python 3,并有2.7版本的mod_wsgi,这似乎很奇怪。 – gin93r
考虑通过使用mod_wsgi-express在命令行上运行WSGI服务器开始。这样你就不需要触摸系统的Apache配置。请参阅https://pypi.python.org/pypi/mod_wsgi和http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html –