3

I'm trying to add a project directory to the PYTHONPATH using pipenv. Following the hint of this post, I created a .env file in order to modify the path used by the virtualenv managed by pipenv.

I created the .env file (in /foo/bar/myProject) as follows:

PYTHONPATH=${PYTHONPATH}:${PWD}

but when I activate the virtualenv, this is the new path:

$ python -c "import sys; print(sys.path)"
['', '/foo/bar/${PYTHONPATH}', '/foo/bar/${PWD}', '/foo/bar/myProject',...]

It correctly adds /foo/bar/myProject to the PYTHONPATH. However, looks like it adds also two extra entries with unsubstituted environment variables.

Why does it happen and how can I avoid this?

Note: I'm using the Z shell (probably it does not matter).

1 Answer 1

4

You probably don't have the $PYTHONPATH envariable set in your shell, so pipenv stupidly replaces ${PYTHONPATH} with the value in the .env file (i.e. ${PYTHONPATH}:${PWD}). Then ${PWD} is successfully expanded, giving you the final value PYTHONPATH=${PYTHONPATH}:${PWD}:/foo/bar/myProject. That leads to the weird looking sys.path. You can fix the issue by omitting ${PYTHONPATH} from the value:

PYTHONPATH=${PWD}

or set it to some value before running pipenv:

export PYTHONPATH=/path/to/dir
pipenv shell

Tested with pipenv version 2018.11.26.

Sign up to request clarification or add additional context in comments.

Comments

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.