I'm using visual studio code to build up a python project. It is my first time to build a project with an Editor(in the past using Pycharm).
As the project gets bigger, I want to import some classes I have written in the other directories(in the same project). First I added the __init__.py
in the directories I want to import from. However, it did not work and it raised:
ModuleNotFoundError: No module named 'LinkedList'
Then I searched on the internet and found that my project path was not in the sys.path. So I added the following in the file where I want to import class:
sys.path.append('D:\\Python_Projects\\Python_DataStructure')
And it worked. I have a question here. How could I permanently add my project path into the sys.path so I did not need to do the sys.path.append in every file where I want to import some classes or functions from other directories?
My project structure currently looked like this:
Python_DataStructure\
LinkedList\
Mylinkedlist.py
__init__.py
Queue\
queue.py
__init__.py
I omitted some python files in the directories above for simplicity