简体   繁体   English

使用扭曲启动python Klein不会引发模块错误

[英]Starting python Klein using twistd throws no module Error

  • Hi, I am trying to start a Klein server using twistd method. 嗨,我正在尝试使用twistd方法启动Klein服务器。 I tried it by reading the Klein documentation . 我通过阅读Klein 文档进行了尝试。
  • But when I tried to start the server, it says no module found. 但是,当我尝试启动服务器时,它说没有找到模块。

Here is the sample code of what i tried, 这是我尝试过的示例代码,

helloworld.py : helloworld.py:

from klein import Klein
from klein import resource, route
app = Klein()

@route('/')
def hello(request):
    return "Hello, world!"

Then I run the following command: 然后我运行以下命令:

twistd -n web --class=helloworld.resource

I got the following error : 我收到以下错误:

File "C:\Python27\lib\site-packages\twisted\python\reflect.py", line 165, in namedObject
    module = namedModule('.'.join(classSplit[:-1]))
  File "C:\Python27\lib\site-packages\twisted\python\reflect.py", line 151, in namedModule
    topLevel = __import__(name)
ImportError: No module named helloworld

Put the directory containing your helloworld.py into the import path. 将包含helloworld.py的目录放入导入路径。 For example, add it to PYTHONPATH : 例如,将其添加到PYTHONPATH

$ PYTHONPATH=${PWD} twistd -n web --class=helloworld.resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM