我通过CherryPy提供django页面。当CherryPy在前台启动时,一切都正常。当我把切里皮和
Daemonizer(cherrypy.engine).subscribe()
我收到了一封信。
sys.path
在这两种情况下(daemonized和non-daemonized)是完全相同的。除了sys.path
影响python导入之外,还有什么可以调试呢?在
回溯:
^{pr2}$/home/fbx/code/plinth/plinth/modules/first_boot/middleware.py
'/home/fbx/code/plinth'
import_module
函数中。在import_module
的参数name
是"plinth.modules.first_boot.middleware"
'plinth.modules.first_boot.middleware.FirstBootMiddleware'
还有一个注意事项:
我用python -m plinth
在目录/home/fbx/code/plinth
运行守护服务器。
当我用/usr/bin/python /home/fbx/code/plinth/plinth/__main__.py
启动守护服务器时,一切正常!在本例中,sys.path
有一个附加条目:/home/fbx/code/plinth/plinth
。但是在启动时手动添加此路径并不能修复以python -m plinth
运行时的ImportError。在
我正在运行以下代码:https://github.com/freedombox/Plinth/tree/0b5af376102f4210395c15b2366b96a6e56fefb2
更新
感谢@cyraxjoe,os.chdir()
加上__init__.py
中丢失的模块是问题所在。对我来说,这种行为是出乎意料的,而且我没有找到很多有用的信息/文档,所以我设置了一个github repo来更容易地演示这个问题:https://github.com/fonfon/ImportError-demo
这只是一个理论,但可能是原因。在
鉴于:
os.chdir('/')
。在plinth.modules.first_boot
显式导入first_boot
,而不是包的__init__.py
上的中间件。在可能是在守护程序插件更改目录之前,导入了模块
plinth.modules.first_boot
,但没有中间件,因此,当django y尝试动态导入模块时,它只是在导入缓存中找到模块,但它找不到中间件,因为路径是相对的,当守护程序插件更改目录时,它就变得不可访问。在尝试导入包的
__init__
上的中间件模块。在基本上在^{} 上添加一个
from . import middleware
相关问题 更多 >
编程相关推荐