2

I am attempting to just run the Hello World code from Tornado docs

import tornado.ioloop
import tornado.web

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

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Except I am getting an error: AttributeError: module 'test' has no attribute '__path__'

I am just using IDLE to run test.py

I thought this was due to my Windows 10 computer not having Python accessible to PATH but even with adding in the python 3.6 to PATH I am still getting the same error. Any ideas?

The screenshot is how I added python to PATH and I think I got it correct..

enter image description here

------EDIT------

Ill add some screenshots of the errors/tracebacks I am running into. 1st one is the command prompt below when the test.py is ran in IDLE 3.6 in Windows 10.

enter image description here

If there is an import error, I can import Tornado just fine thru IDLE interpreter. enter image description here

I also tried running this hello World code in IPython 3.7, and I get this error: enter image description here

10
  • Please post the full error traceback. Commented Jan 4, 2019 at 6:00
  • Can you give me a tip on how to do a full error trace back? Commented Jan 4, 2019 at 8:47
  • Post the full error message that you're getting. Commented Jan 4, 2019 at 9:14
  • I added some screenshots Commented Jan 4, 2019 at 16:09
  • Odd in Ipython even restarting the kernel & rerunning the code the same error always popped up the loop was running Commented Jan 4, 2019 at 16:25

1 Answer 1

8

Solution: Run your file without the -m argument.

Another solution would be to provide the file name without the .py extension:

python -m test

This will also work.


Explanation:

The -m argument tells Python to run a module (file) present in the Python path. It doesn't take the name of the file, it takes the name of the module. The difference is that the file name contains .py suffix, whereas the module name doesn't.

So you can run the test.py file like this, too: python -m test.


When to use -m argument:

The -m argument is there for convenience. For example, if you want to run python's default http server (which comes with python), you'd write this command:

python -m http.server

This will start the http server for you. The convenience that -m argument gives you is that you can write this command from anywhere in your system and python will automatically look for the package called http in your the system's Path.

Without the -m argument, if you wanted to run the http server, you'd have to give it's full path like:

python C:\path\to\python\installation\http\server.py

So, -m argument makes it easy to run modules (files) present in the Path.


With Tornado would you happen to know how to kill the Python interpreter? A CNTRL-C doesn't do anything.

I use Linux and Ctrl-C works fine for me. On Windows you can try Ctrl-D or Ctrl-Z. Or here are some answers: Stopping python using ctrl+c

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.