Python Tornado AttributeError:模块"test"没有属性"__path__" [英] Python Tornado AttributeError: module 'test' has no attribute '__path__'

查看:238
本文介绍了Python Tornado AttributeError:模块"test"没有属性"__path__"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅运行 Tornado文档Hello World代码>

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()

除了出现错误:AttributeError: module 'test' has no attribute '__path__'

我只是使用IDLE来运行test.py

I am just using IDLE to run test.py

我认为这是由于我的Windows 10计算机没有PATH可访问的Python,但是即使将python 3.6添加到PATH中,我仍然遇到相同的错误.有什么想法吗?

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?

屏幕快照是我将python添加到PATH的方式,我认为我没错.

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

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

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

我将添加一些我遇到的错误/回溯的屏幕截图.第一个是下面的命令提示符,当在Windows 10的IDLE 3.6中运行test.py时.

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.

如果出现导入​​错误,我可以通过IDLE解释器很好地导入Tornado.

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

我也尝试在IPython 3.7中运行此hello World代码,但出现此错误:

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

推荐答案

解决方案:在不使用-m参数的情况下运行文件.

Solution: Run your file without the -m argument.

另一种解决方案是提供不带.py扩展名的文件名:

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

python -m test

这也将起作用.

说明:

-m参数告诉Python运行Python路径中存在的模块(文件).它不使用文件名,而是使用模块名.区别在于文件名包含后缀.py,而模块名不包含后缀.

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.

因此,您也可以像这样运行test.py文件:python -m test.

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

何时使用-m参数:

When to use -m argument:

为方便起见,这里有-m参数.例如,如果您要运行python的默认http服务器(python随附),则可以编写以下命令:

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

这将为您启动http服务器. -m参数给您带来的便利是,您可以从系统中的任何位置编写此命令,而python将在系统的Path中自动查找名为http的软件包.

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.

没有-m参数,如果要运行http服务器,则必须给出其完整路径,例如:

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

因此,-m参数使运行Path中存在的模块(文件)变得容易.

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

借助Tornado,您是否会知道如何杀死Python解释器? CNTRL-C不执行任何操作.

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

我使用Linux,而Ctrl-C对我来说工作正常.在Windows上,您可以尝试Ctrl-DCtrl-Z.或以下是一些答案:使用ctrl + c停止python

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

这篇关于Python Tornado AttributeError:模块"test"没有属性"__path__"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆