Example folder setup:
Let say i am in other random folder,eg
G:\div\ Menu\ |-- launch.pyIn
lanuch.py
print('i am launch')Let say i have this code in VS Code ,and i am in
G:\div
folder.import sys import os #print(sys.path) print(os.getcwd()) import Menu.launch
g:\div i am launchNow the import work because current working directory
cwd
is always added to sys.path
Let say i am in other random folder,eg
C:\bar
import sys import os #print(sys.path) print(os.getcwd()) import Menu.launch
Output:c:\bar
Traceback (most recent call last):
File "c:\bar\ren.py", line 7, in <module>
import Menu.launch
ModuleNotFoundError: No module named 'Menu'
Now it dos not work,i have to add G:\div
(not launch) to sys.path
so Python can find it when in bar
folder.import sys import os #print(sys.path) print(os.getcwd()) sys.path.append(r'G:\div') import Menu.launch
c:\bar i am launch