无法从另一个python文件(在另一个目录中)调用函数

时间:2020-09-15 10:17:24

标签: python python-3.x python-import

在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'

我有什么选择来解决这个问题?


我经历了与此相关的其他答案,它们对我不起作用...主要是因为它们不像我的情况那样处理工作目录。

0 个答案:

没有答案
相关问题