Skip to content

Python Environment Options


Env a vs b

pipenv & pyenv

note from 2018-09-06:

Pipenv does not respect pyenv’s global and local Python versions¶ Pipenv by default uses the Python it is installed against to create the virtualenv. You can set the --python option, or $PYENV_ROOT/shims/python > to let it consult pyenv when choosing the interpreter. See ☤ Specifying Versions of a Package for more information.

If you want Pipenv to automatically “do the right thing”, you can set the environment variable PIPENV_PYTHON to $PYENV_ROOT/shims/python. This > will make Pipenv use pyenv’s active Python version to create virtual environments by default.

pyenv+vitrualenvwrapper or pyenv+pipenv

Note from 2019-09-06:

You have two options:

use pyenv and pyenv-virtualenv wrapper together.

For example, you want to create a new project test and also want to create a virtual env for it.

pyenv install 3.6.5
pyenv virtualenv 3.6.5 test
cd /project_path
pyenv local test

Next time, you access the project dir, it will change to test environment automatically

use pyenv and pipenv together

Firstly, add this script to the env config(bashrc or zshenv, etc.)

export PIPENV_VENV_IN_PROJECT=1 PROMPT_COMMAND='prompt' precmd() { eval "$PROMPT_COMMAND" } function prompt() { if [ ! $PIPENV_ACTIVE ]; then if [pipenv --venv 2>/dev/null]; then export PIPENV_INITPWD="$PWD" pipenv shell fi elif [ $PIPENV_INITPWD ] ; then cd "$PIPENV_INITPWD" unset PIPENV_INITPWD fi }


pyenv install 3.6.5
pyenv shell 3.6.5
pip install pipenv
cd /project_path
pipenv --python 3.6.5

Next time you access the directory, it will change to the correct vent(note: you should use pyenv shell 3.6.5 before you access the project dir)

REF : StackOverflow post