I am using Python 3.6.0 and having trouble with a project across several directories. The directory structure looks like this:
/project
/project/frontend
All the functionality of my frontend is finished and tested locally and lives in /project/frontend
and I now want to connect it with my backend which lives in /project
So I changed into /project/frontend
and ran display_page.py
which contains the lines:
sys.path.append('../')
from text_algorithms import process_text
..where text_algorithms.py
sits in /project
and works fine when run from there. So it started running for a good thirty seconds then crashed, complaing that it couldn't find its pickle file which sits in /project
There is never a problem when text_algorithms.py
is run or imported from /project
text_algorithms.py
contains the lines:
with open('english_vocab.pickle', 'rb') as f:
v = pickle.load(f)
So I thought I could 'fool' it by running python frontend/display_page.py
from the directory below but that created a different error, namely,
ModuleNotFoundError: No module named 'text_algorithms'
Does anyone know how to fix this? - how to make sure that it will not change where it looks for that file depending on where you call it from. Is there a proper way to deal with this situation?
It should find its file wherever it is run from.