Public repo for my person dotfiles and config notes.
$ brew install pyenv-virtualenv
After installation, you'll still need to add
# Pyenv setup
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
to your .bashrc profile (as stated in the caveats). You'll only ever have to do this once.
To create a virtualenv for the Python version used with pyenv, run
pyenv virtualenv
, specifying the Python version you want and the name
of the virtualenv directory. For example,
$ pyenv virtualenv 2.7.10 my-virtual-env-2.7.10
will create a virtualenv based on Python 2.7.10 under $(pyenv root)/versions
in a
folder called my-virtual-env-2.7.10
.
If there is only one argument given to pyenv virtualenv
, the virtualenv will
be created with the given name based on the current pyenv Python version.
$ pyenv version
3.4.3 (set by /home/yyuu/.pyenv/version)
$ pyenv virtualenv venv34
pyenv virtualenvs
shows you the list of existing virtualenvs and conda
environments.
$ pyenv shell venv34
$ pyenv virtualenvs
miniconda3-3.9.1 (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
miniconda3-3.9.1/envs/myenv (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
2.7.10/envs/my-virtual-env-2.7.10 (created from /home/yyuu/.pyenv/versions/2.7.10)
3.4.3/envs/venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)
my-virtual-env-2.7.10 (created from /home/yyuu/.pyenv/versions/2.7.10)
* venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)
There are two entries for each virtualenv, and the shorter one is just a symlink.
Some external tools (e.g. jedi) might
require you to activate
the virtualenv and conda
environments.
If eval "$(pyenv virtualenv-init -)"
is configured in your shell, pyenv-virtualenv
will automatically activate/deactivate virtualenvs on entering/leaving directories which contain a .python-version
file that lists a valid virtual environment. .python-version
files denote local Python versions and can be created and deleted with the pyenv local
command.
You can also activate and deactivate a pyenv virtualenv manually:
pyenv activate <name>
pyenv deactivate
Removing the directories in $(pyenv root)/versions
and $(pyenv root)/versions/{version}/envs
will delete the virtualenv, or you can run:
pyenv uninstall my-virtual-env
There is a venv module available
for CPython 3.3 and newer.
It provides an executable module venv
which is the successor of virtualenv
and distributed by default.
pyenv-virtualenv
uses python -m venv
if it is available and the virtualenv
command is not available.