VS CODE 1.52.1 Python 3.7.9
Path structure
- MyWorkspace
- Folder Main
- MyWorkspace.code-workspace
- MainModule.py
- Folder A
- SubModule_A.py
- Folder B
- SubModule_B.py
- Folder Main
In the past, I could import "MainModule.py" in all of sub-modules in any directory easily like below.
import MainModule
But after I reinstall VS Code, they are unable to find modules in different paths. I've found some solutions importing modules with absolute paths, but there are hundreds sub-modules already making hard to modify them all.
I tried below but nothing works.
- Modifying cwd
In "SubModule_a.py",
import os
os.chdir("C:\\work\\Folder Main")
import MainModule
This still arises ModuleNotFoundError
Modifying "MyWorkspace.code-workspace"
"settings": {
"python.pythonPath": "C:\\anaconda3\\envs\\MyEnv\\python.exe", # for virtual env "python.linting.pylintEnabled": true, "python.linting.enabled": true, "terminal.integrated.cwd": "C:\\work\\Folder Main" # added this line}
In short, how can I import "MainModule.py" from "SubModule_A.py" without using absolute path?

