My PyCharm project contains folders such as src
, data
, notebooks
etc.
Within my notebooks folder, I have a small notebooks.py
file which contains:
import sys
sys.path.append('../src')
So within my notebooks, I do the following:
import notebooks
import preprocessing.some_module
However, all my code is naturally within src
and is full of imports such as:
from src.preprocessing.some_module import SomeClass
So when I try to import something within the notebooks, I get errors telling me src is not found
.
If I set the content root at src
within the Project Structure, all the other folders simply disappear so it's not really a solution.
So, is there a way for me to be able to refer to my project modules simply as preprocessing.some_module
rather than src.preprocessing.some_module
so that I can run my code smoothly both using PyCharm and on AWS?
Also, I have a bunch of constants in my code such as:
SOME_FOLDER = '../../data/some_folder'
These work fine for now, while I run from PyCharm but I fear this relativity might also get messed up when I start running the code from Jupyter. What is the best way to define these paths so they work no matter what?