I can't for the life of me figure out what's wrong here. I'm trying to import a local library that's in an upstream path:
root/
folder1/
test1.py
folder2/
test2.py
In this scenario I want to import folder1
in test2.py
.
In test2.py
, I use sys.path.append
to add the file path to folder1
:
import os
import sys
fileDir = os.path.dirname(os.path.abspath(__file__))
parentDir = os.path.dirname(fileDir)
sys.path.append(os.path.join(parentDir, 'folder1'))
print(sys.path)
import folder1.test1
But when I'm in root and run python3 folder2/test2.py
, I still get ModuleNotFoundError: No module named 'folder1'
.
I've also tried hardcoding $PYTHONPATH
and it still doesn't work.