Cannot import Tornado submodules

故事扮演 提交于 2019-12-05 10:53:31

问题


Trying to install Tornado for first time (On EC2 Linux instance). I did

pip install tornado

and then tried running the hello world example: http://www.tornadoweb.org/en/stable/#hello-world

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(80)
    tornado.ioloop.IOLoop.instance().start()

I then try:

python hello.py

but get:

Traceback (most recent call last): File "testing/tornado.py", line 1, in
import tornado.ioloop File "/opt/pdf_engine/testing/tornado.py", line 1, in
import tornado.ioloop ImportError: No module named ioloop


回答1:


Don't name your file tornado.py; it shadows the actual Tornado import. Name it something like what you used in your example, e.g. hello.py

Right now, your import tornado.ioloop is trying to import the member ioloop from your own file, because it's named tornado and in the current directory which has the highest import precedence.




回答2:


If you named your file tornado.py and rename it to another name,don't forget to remove tornado.pyc in your directory.



来源:https://stackoverflow.com/questions/17323568/cannot-import-tornado-submodules

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!