简体   繁体   English

Windows上具有mod_wsgi的Python 3.6 Flask:没有名为queue的模块

[英]Python 3.6 Flask with mod_wsgi on Windows : No module named queue

I was playing around with a Flask/Python RESTful api and all was well until I started trying to learn how to serve it. 我一直在使用Flask / Python RESTful API,直到开始尝试学习如何使用它为止,一切都很好。 Of course I tried this out locally. 当然,我在本地尝试过。

I installed AMPPS since it comes with python and mod_wsgi installed and enabled by default. 我安装了AMPPS,因为它附带了python和mod_wsgi,并且默认情况下已安装并启用。 I went through all of the setups and I was able to get the default "Hello World!" 我完成了所有设置,然后获得了默认的“ Hello World!”。 application to work. 申请工作。 Huzzah! 好哇! Right? 对?

Then I tried to start bringing in my app and this is where I've hit the road blocks. 然后我尝试开始引入我的应用程序,这就是我遇到的障碍。

At first, I was getting an error that there was no module named flask. 一开始,我遇到一个错误,即没有名为flask的模块。 After some reading I learned that I need to load my virtualenv like so: 经过一番阅读后,我得知我需要像这样加载我的virtualenv:

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

This seemed to work with flask, but then I got: 这似乎适用于flask,但是后来我得到了:

ModuleNotFoundError: No module named 'queue'

I've scoured the interwebs and have read about "queue" vs "Queue" but I'm not importing it directly. 我已经搜索了互连网,并阅读了有关“队列”和“队列”的信息,但我没有直接导入它。

Here is the code that I have currently. 这是我目前拥有的代码。

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]

Any help would be appreciated. 任何帮助,将不胜感激。

Your mod_wsgi is actually compiled for Python 2.7, not 3.6. 您的mod_wsgi实际上是为Python 2.7而不是3.6编译的。 The error is because the Queue module got renamed to queue in 3.6, so when import queue under 2.7 it will fail. 该错误是因为Queue模块在3.6中被重命名为queue ,所以当2.7以下的导入queue时,它将失败。

You will need to uninstall mod_wsgi and install a version of if that is compiled for Python 3.6. 您将需要卸载mod_wsgi并安装的版本(如果该版本是针对Python 3.6编译的)。 You cannot force a version of mod_wsgi compiled for one Python version to run as a different version by pointing it at a Python virtual environment of a different version. 您不能通过将针对一个Python版本编译的mod_wsgi版本指向另一个版本的Python虚拟环境来使其强制作为另一个版本运行。 This is because mod_wsgi is linked direct to the Python library of a specific version. 这是因为mod_wsgi直接链接到特定版本的Python库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM