尝试加载 Python 模块时出现 ModuleNotFoundError,一切正常

Getting a ModuleNotFoundError when trying to load a Python Module and all seems ok

我有一个树结构

 - My_app    
   - __init__.py
   - main.py
   - Cus_Scripts  
      - __init__.py
      - script1.py
      - script2.py - classA

我是运行这样的

在 script1 中,我收到一个 ModuleNotFoundError,提示找不到 script2。我正在使用 VSC。

我通过将此添加到每个文件来修复此问题。


#Custom Lib
sys.path.insert(1, os.getcwd())

这让我可以通过

访问程序的任何部分

from My_App.script2 import classA
import My_App.script1