Python Tornado:ImportError:没有名为“tornado”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35049162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Tornado: ImportError: No module named 'tornado'
提问by 90abyss
This is my tornado file::
这是我的龙卷风文件::
from tornado.wsgi import WSGIContainer
from tornado.ioloop import IOLoop
from tornado.web import FallbackHandler, RequestHandler, Application
from flasky import app
class MainHandler(RequestHandler):
def get(self):
self.write("This message comes from Tornado ^_^")
tr = WSGIContainer(app)
application = Application([
(r"/tornado", MainHandler),
(r".*", FallbackHandler, dict(fallback=tr)),
])
if __name__ == "__main__":
application.listen(5000)
IOLoop.instance().start()
Basically I'm running a flask server in Tornado. But I'm getting this error:
基本上我在 Tornado 中运行一个烧瓶服务器。但我收到此错误:
from tornado.wsgi import WSGIContainer ImportError: No module named 'tornado'
from tornado.wsgi import WSGIContainer ImportError: No module named 'tornado'
I've already gone through this post: Python Tornado: WSGI module missing?
我已经阅读了这篇文章:Python Tornado:缺少 WSGI 模块?
But my file is not named Tornado.py so that doesn't apply to me.
但是我的文件没有命名为 Tornado.py,所以这不适用于我。
Please help.
请帮忙。
回答by Mohamed Abdeljelil
check if tornado module is installed with pip and if you are using a virtualenv check if it's activated
检查 Tornado 模块是否与 pip 一起安装,如果您使用的是 virtualenv 检查它是否已激活
回答by A. Jesse Jiryu Davis
A common problem is having multiple Python interpreters, or multiple Python environments, installed. "pip" and "python" may use different environments. Try installing Tornado like this:
一个常见问题是安装了多个 Python 解释器或多个 Python 环境。“pip”和“python”可能使用不同的环境。尝试像这样安装 Tornado:
python -m pip install tornado
回答by Sandeep Goswami
I got rid of this by using following command.
我通过使用以下命令摆脱了这个。
sudo python3 -m pip install tornado
回答by Ketan Mahajan
I faced the issue while testing tornado for the first time. It was because I named the file as tornado.py (as also mentioned by Mohamed Abdelijelil). I renamed it to tornado_test.py and it worked.
我在第一次测试龙卷风时遇到了这个问题。这是因为我将文件命名为 tornado.py(Mohamed Abdelijelil 也提到过)。我将它重命名为 tornado_test.py 并且它起作用了。