1

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 ?

1 Answer 1

6

I realized I can use .env files to setup PYTHONPATH and make pipenv use it.

echo "PYTHONPATH=${PWD}" >> .env 
Sign up to request clarification or add additional context in comments.

1 Comment

It's safer to use >>: echo "PYTHONPATH=${PWD}" >> .env

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.