I have the following structure
.
├── module1
│ ├── __init__.py
│ └── start.py
├── module2
│ ├── __init__.py
│ └── settings.py
└── Pipfile
cat module1/start.py
from module2.settings import VAR
if __name__ == '__main__':
print(VAR)
cat module2/settings.py
VAR = 'foo'
If I try to run my program I get
pipenv shell
python module1/start.py
Traceback (most recent call last):
File "module1/start.py", line 1, in <module>
from module2.settings import VAR
ModuleNotFoundError: No module named 'module2'
or
pipenv run python module1/start.py
Traceback (most recent call last):
File "module1/start.py", line 1, in <module>
from module2.settings import VAR
ModuleNotFoundError: No module named 'module2'
Why doesn't pipenv set PYTHONPATH correctly ?
Will Vousden
33.6k9 gold badges89 silver badges97 bronze badges
asked Oct 25, 2018 at 9:59
zzart
11.6k5 gold badges56 silver badges47 bronze badges
1 Answer 1
I realized I can use .env files to setup PYTHONPATH and make pipenv use it.
echo "PYTHONPATH=${PWD}" >> .env
answered Oct 25, 2018 at 11:11
zzart
11.6k5 gold badges56 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
givemesnacks
It's safer to use
>>: echo "PYTHONPATH=${PWD}" >> .envlang-py