Python 子文件夹中的ModuleNotFoundError

Python 子文件夹中的ModuleNotFoundError,python,python-3.x,python-import,Python,Python 3.x,Python Import,我通常认为互联网上也有类似的答案,所以如果有,请直接告诉我。我已经搜索了几个小时,所以决定询问社区 我不熟悉测试和尝试设置以下结构(在Windows环境中): 文件A内容: import fileB # do something test_fileA内容(仅尝试先让导入工作): 我正在运行的代码/收到的错误是 C:\parentFolder >> python -m tests.test_fileA ... File "C:\parentFolder\src\fil

我通常认为互联网上也有类似的答案,所以如果有,请直接告诉我。我已经搜索了几个小时,所以决定询问社区

我不熟悉测试和尝试设置以下结构(在Windows环境中):

文件A内容:

import fileB

# do something
test_fileA内容(仅尝试先让导入工作):

我正在运行的代码/收到的错误是

C:\parentFolder >> python -m tests.test_fileA

...
File "C:\parentFolder\src\fileA.py", line 14, in <module>
    import fileB
ModuleNotFoundError: No module named 'fileB'
C:\parentFolder>>python-m tests.test\u文件a
...
文件“C:\parentFolder\src\fileA.py”,第14行,在
导入文件B
ModuleNotFoundError:没有名为'fileB'的模块
我猜这与相对路径有关?我可以使用
来自。导入文件B
但这感觉有点不舒服。正确的解决办法是什么

import src.fileB
如果你真的不想使用相对路径,应该可以,但据我所知,使用
import.fileB
没有缺点


如果你想了解更多关于导入内容的信息,我建议你写这篇文章:

检查当前工作目录是否设置为正确的路径。如果您是从父文件夹运行的,那么它应该是从src import fileB运行的
,那么在该文件夹中相互调用的所有文件是否都需要追加?从我的命令行运行pythonfilea.py运行良好。
C:\parentFolder >> python -m tests.test_fileA

...
File "C:\parentFolder\src\fileA.py", line 14, in <module>
    import fileB
ModuleNotFoundError: No module named 'fileB'
import src.fileB