我有以下文件夹结构
project
+folder src
+file main.py
+file __init__.py
+folder tests
+file test.py
+file __init__.py
+file __init__.py
所有__init__
文件都是空的。
现在我希望能够在任何地方test.py
运行表单,这很重要。
test.py
来电
import src
因为它需要来自main.py
. 这会导致错误:
ImportError: no module named src
我找到的解决方案包括向我的环境变量添加sys.path.append
命令test.py
或将文件夹 src 添加到我的PATH
环境变量中 - 没有其他方法吗?
我不能强迫每个用户更改他们的PATH
,也不能向所有测试文件添加sys.path.append
命令。