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..
------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.
If there is an import error, I can import Tornado just fine thru IDLE interpreter.
I also tried running this hello World
code in IPython 3.7, and I get this error:
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