在ubuntu上,我正在使用以下结构:
.
├── src
│ ├── __init__.py
│ └── main.py
└── test
├── __init__.py
└── test.py
main.py
包含以下功能:
def fun(x,y):
return x+y
test.py有
from src.main import fun
print(fun(2,3))
我正在目录daddy
中工作。因此pwd
打印daddy
。
当我尝试致电test.py
时,
$ python3 test/test.py
Traceback (most recent call last):
File "test/test.py", line 1, in <module>
from src.main import fun
ModuleNotFoundError: No module named 'src'
我经历了与此相关的其他答案,它们对我不起作用...主要是因为它们不像我的情况那样处理工作目录。