【发布时间】:2014-06-04 21:50:10
【问题描述】:
我有一个按以下方式设置的项目目录:
>root
> modules
__init__.py
module1.py
> moduleClass
__init__.py
moduleClass1.py
moduleClass2.py
> scripts
runTests.py
> tests
__init__.py
test1.py
test2.py
run.sh
在runTests.py 我有以下导入语句:
import modules.module1
import modules.moduleClass.moduleClass2
import tests.test1
import tests.test2
前两个导入语句工作正常,但后两个给我错误ImportError: No module named test1 和ImportError: No module named test2。我看不出测试和模块目录之间有什么不同。
我很乐意根据需要提供更多信息。
【问题讨论】:
-
运行 runTests.py 时你的工作目录是什么?
-
那个目录下__init__.py的内容是什么?
-
尝试重现,我在第一次导入时出错
-
@JohannesKeinestam 我从 root 运行 runTests.py。
-
@BartoszKP 所有
__init__.py文件都是空的,尽管我确实尝试使用路径添加语句。
标签: python python-import