我有一个python程序,其中出现以下错误:
ImportError: No module named core
导致错误的导入是:
from core import wcolors
文件wcolors.py
位于名为core
的目录中,还有另一个名为modules的目录,因此当我运行程序时,它会给出以下错误输出:
Traceback (most recent call last):
File "anubis.py", line 7, in <module>
from core import wcolors
ImportError: No module named core
目录结构
dir结构如下
anubis
--anubis.py (the script that i run)
--core
--wcolors.py (the file i import from core)
-- modules
[the modules i suposed to load during the execution.]
作为另一个细节,core中的所有文件都是用.pyc扩展名编译的。你知道吗
你可以试试这个:
或者您可以更改“core”的名称,它可以是django和python的关键字。你知道吗
您只需要在
anubis
和anubis/core
目录中添加一个空的__init__.py
,这样应该可以。如果没有__init__.py
文件,python不会认为目录是一个模块。你知道吗Python docs
相关问题 更多 >
编程相关推荐