20

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

2 Answers 2

49

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.

6
  • How to stop the server. I also tried hello world example. But I don't know how to stop it Aug 24, 2013 at 12:25
  • Try Ctrl+C to stop it.
    – Amber
    Aug 24, 2013 at 16:47
  • 9
    And it's highly probable that you have to remove the tornado.pyc that was generated
    – Robert
    Jan 6, 2014 at 14:28
  • +1 On some answers I really wish I could apply more than just one upvote!
    – Levite
    Jun 26, 2014 at 11:54
  • 1
    its fake solution :( Jan 27, 2017 at 17:15
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.