Windows上具有mod_wsgi的Python 3.6 Flask:没有名为queue的模块 [英] Python 3.6 Flask with mod_wsgi on Windows : No module named queue

查看:68
本文介绍了Windows上具有mod_wsgi的Python 3.6 Flask:没有名为queue的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Flask/Python RESTful API,直到开始尝试学习如何使用它为止,一切都很好.当然,我是在本地尝试过的.

I was playing around with a Flask/Python RESTful api and all was well until I started trying to learn how to serve it. Of course I tried this out locally.

我安装了AMPPS,因为它默认安装并启用了python和mod_wsgi.我完成了所有设置,然后获得了默认的"Hello World!".申请工作.头晕!对吧?

I installed AMPPS since it comes with python and mod_wsgi installed and enabled by default. I went through all of the setups and I was able to get the default "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.

起初,我遇到一个错误,即没有名为flask的模块.经过一番阅读后,我得知我需要像这样加载我的virtualenv:

At first, I was getting an error that there was no module named flask. After some reading I learned that I need to load my virtualenv like so:

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:

ModuleNotFoundError:没有名为队列"的模块

我已经搜索了互连网,并阅读了有关队列"和队列"的信息,但我没有直接导入它.

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]

任何帮助将不胜感激.

推荐答案

您的mod_wsgi实际上是针对Python 2.7而不是3.6编译的.该错误是因为 Queue 模块在3.6中被重命名为 queue ,所以当在2.7以下导入 queue 时,它将失败.

Your mod_wsgi is actually compiled for Python 2.7, not 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.

您将需要卸载mod_wsgi并安装if的版本,该版本是针对Python 3.6编译的.您不能通过将针对一个Python版本编译的mod_wsgi版本指向另一个版本的Python虚拟环境来使其强制运行为另一个版本.这是因为mod_wsgi直接链接到特定版本的Python库.

You will need to uninstall mod_wsgi and install a version of if that is compiled for 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. This is because mod_wsgi is linked direct to the Python library of a specific version.

这篇关于Windows上具有mod_wsgi的Python 3.6 Flask:没有名为queue的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆