@KindNotice: I've searched the current treads like this one or this one for potential solution. However, I still have troubles to gather every information together and find the optimal and working setup. Although my case is probably less general, it tries to connect the dots from different places at SO. Please take this into consideration before marking as a duplicate.
My project is structured like this:
my-project/
src/
model.py
utils.py
__init__.py
notebooks/
test.py
In model.py
I have an import:
from utils import my_function
My working directory is set to my-project
(as returned by os.getcwd()
). I am using Conda environment, and tried to amend PYTHONPATH
as suggested here with:
"env": {"PYTHONPATH": "${workspaceRoot}, ${workspaceRoot}/src"}
I also have __init__.py
within my src
directory. From my understanding, if I use from src.utils import my_function
it would work fine within VSCode - however, when running from bash terminal from the src
directory (where the model.py
script is located). To add to all of that I'd like to be able to import my modules in jupyter notebook files located in notebooks
.
What's the best setup to be able to import scripts from another modules from src
here? Is editing PYTHONPATH
really neccesary here? (I can't see any effect of that).