导入错误:无法导入名称
出于某种原因,每次我尝试从另一个文件导入一个类时,都会收到一个ImportError
错误。我的项目的GitHub页面是:https://github.com/wheelebin/mcnextbot
这是我收到的错误信息:
Traceback (most recent call last):
File "ircbot.py", line 36, in <module>
from test import mcnextlvl
ImportError: cannot import name mcnextlvl
2 个回答
1
__init__.py
这个 Python 文件让你可以从 lib 包中导入你自己命名为 'test' 的模块。
1
这里你的 from test import something
是在引用 <PYTHONPATH>/lib
里的 test
模块,而不是你自己的 test.py
文件,并且那里没有叫 mcnextlvl
的子模块或类。你应该像 @sgmart 评论的那样使用 from lib.test import mcnextlvl
。