我的项目设置如下:
项目
-concrete_classes
-test_module.py
-unit_tests
-unit_tests_test_module.py
-main.py
在main.py中,我可以“从concrete_classes导入test_module” 在unit_tests_test_module.py中,我无法“从concrete_classes导入test_module”(ModuleNotFoundError:没有名为“ concrete_classes”的模块)。如果我尝试“导入concrete_classes.test_module”,同样的问题
我正在使用本指南作为参考:https://www.internalpointers.com/post/modules-and-packages-create-python-project,即“从上方导入模块”部分,看来我在做与他们完全一样的事情。
我要去哪里错了?
一些搜索告诉我,这可能是我的系统路径存在问题,但是我不确定在查看sys.path时会看到什么
答案 0 :(得分:0)
我经常使用的一种解决方案是将您的项目根目录添加到您的系统路径中:
import sys
sys.path.append("/path/to/project")
然后,您可以安全地导入所有子模块。