I'm trying to work on a project with a structure as follows:
root_folder
├── __init__.py
├── a_folder
│ ├── __init__.py
│ └── script_1.py
├── b_folder
│ ├── __init__.py
│ └── script_2.py
└── script_3.py
I open the IDE (VS Code) on the root_folder. And I add the empty __init__.py
file to both the sub-folder and the root_folder. I also save all and restart the IDE.
However, when I try to import the script_1
in script_2
, the error appears:
# in script_2.py
from a_folder import script_1
ModuleNotFoundError: No module named 'script_1'
I also try many other ways, like
# in script_2.py
from root_folder.a_folder import script_1
# Or
from .a_folder import script_1
But they still don't work. I searched everywhere but still cannot solve it. Could you mind giving me some hints on it? Thank you!
Update
Here are some print results of the path:
# when I try to run script_2 in b_folder
print(os.path.abspath(''))
print(os.getcwd())
---/home/nick/Desktop/root_folder
---/home/nick/Desktop/root_folder
print(sys.path)
---
['/home/nick/Desktop/root_folder/b_folder', '/home/nick/anaconda3/envs/pytorch101/lib/python37.zip', '/home/nick/anaconda3/envs/pytorch101/lib/python3.7', '/home/nick/anaconda3/envs/pytorch101/lib/python3.7/lib-dynload', '/home/nick/anaconda3/envs/pytorch101/lib/python3.7/site-packages']