在文件foo中,我正在导入模块:
import lib.helper_functions
import lib.config
在helper_functions.py中,我有以下内容:
import config
当我运行foo的主函数时,会出现ImportError错误。
编辑:下面是我拥有的文件结构。
foo.py
lib/
config.py
helper_functions.py
导致错误的原因是在 helper_functions 中导入了 config。
Traceback (most recent call last):
File "C:\Python33\foo.py", line 1, in <module>
import lib.helper_functions
File "C:\Python33\lib\helper_functions.py", line 1, in <module>
import config
ImportError: No module named 'config'
所以说:当我运行foo.py时,解释器会抱怨helper_functions的导入语句。但是当我运行helper_functions的主函数时,却没有出现任何错误。
ImportError
,那是一个非常不同的错误。 - Martijn Pieters