我的包裹有这样的结构:
/code_trou
__init__.py
Main.py
Menu.py
/postprocessing
/preprocessing
Mesh.py
Point.py
/processing
FDM.py
/tools
dllmrg.py
errormrg.py
/__pycache_
errormrg.cpython-35.pyc
执行Main.py
时:
我有这个错误:"No module named 'tools'"
执行Point.py
时也是一样的:
from tools.dllmrg import *
对于Point.py
我尝试了the Intra-package References described in the doc,但似乎没有起作用:我在执行Point.py
时得到了错误"Parent module '' not loaded, cannot perform relative import"
,取而代之的是:
from ..tools.dllmrg import *
使目录成为Python包的原因是
__init__.py
文件的存在。您的tools
和processing
目录中没有这样的文件,因此Python不会将它们识别为包。在https://docs.python.org/3/tutorial/modules.html#packages
相关问题 更多 >
编程相关推荐