pyenv is a tool to allow multiple versions of the Python interpreter to be installed at the same time.
pyenv works by filling a shims directory with fake versions of the Python interpreter (plus other tools like pip and 2to3). When the system looks for a program named python, it looks inside the shims directory first, and uses the fake version, which in turn passes the command on to pyenv. pyenv then works out which version of Python should be run based on environment variables, .python-version files, and the global default.
pip and virtual environment
In order to make sure that you install packages to your active virtual environment when you use pip install, consider adding the following lines to your ~/.bashrc (or ~/.zshrc) file:
After saving this change and sourcing the ~/.bashrc file (or ~/.zshrc) with source ~/.bashrc (or source ~/.zshrc), pip will no longer let you install packages if you are not in a virtual environment. (But you can use gpip install packages globally. )
You can also do this configuration by editing your pip.conf or pip.ini file.
pyenv, pip and virtual environment
pyenv and how does it work ?
pyenv
is a tool to allow multiple versions of the Python interpreter to be installed at the same time.pyenv
works by filling ashims
directory with fake versions of the Python interpreter (plus other tools like pip and 2to3). When the system looks for a program namedpython
, it looks inside theshims
directory first, and uses the fake version, which in turn passes the command on topyenv
.pyenv
then works out which version of Python should be run based on environment variables,.python-version
files, and the global default.pip and virtual environment
In order to make sure that you install packages to your active virtual environment when you use
pip install
, consider adding the following lines to your~/.bashrc
(or~/.zshrc
) file:After saving this change and sourcing the
~/.bashrc
file (or~/.zshrc
) withsource ~/.bashrc
(orsource ~/.zshrc
),pip
will no longer let you install packages if you are not in a virtual environment. (But you can usegpip
install packages globally. )You can also do this configuration by editing your
pip.conf
orpip.ini
file.References