ImportError:无法导入名称

时间:2014-04-25 01:01:15

标签: python python-2.7 import importerror

出于某种原因,每次尝试从其他文件导入类时,我都会收到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 个答案:

答案 0 :(得分:1)

此处from test import something引用test中的模块<PYTHONPATH>/lib,而非test.py,并且没有子模块/类mcnextlvl。您应该使用from lib.test import mcnextlvl作为@sgmart评论。

答案 1 :(得分:1)

__init__.py python文件允许您导入名为&#39; test&#39;的单个模块。来自lib包。