If you use pyenv, you can select the Python version for each directory and it will not pollute the environment, but pip is installed globally and you can not manage it for each project.
In such a case, by using virtualenv, you can prepare a Python virtual environment and manage Python versions and modules in it. And the virtualenv wrapper is a more convenient extension of that virturalenv. It seems.
Can be installed with brew
$ brew install pyenv-virtualenvwrapper
Describe the following in ~ / .bashrc
and ~ / .zshrc
$ vim ~/.zshrc
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
pyenv virtualenvwrapper
$ source ~/.zshrc
Reference: https://github.com/yyuu/pyenv-virtualenvwrapper
$ mkvirtualenv testenv
(testenv) $
You can create a virtual environment with mkvirtualenv ENVNAME
. ENVNAME is the name of the virtual environment.
If you are in a virtual environment, (testenv) $
and the virtual environment name will be displayed at the prompt.
Try to see if the environment is really different.
(testenv)$ pip list
pip (1.5.6)
setuptools (3.6)
pip list
displays a list of packages installed with pip.
Exit the virtual environment and try to display pip list
in the normal environment. Use the deactivate
command to exit the virtual environment.
(testenv)$ deactivate
$ pip list
argparse (1.2.1)
pip (1.5.6)
setuptools (5.4.1)
stevedore (0.15)
virtualenv (1.11.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.1)
It can be seen that the normal environment and the virtual environment are firmly separated. If you want to enter the created virtual environment, enter it with the following command.
$ workon testenv
(testenv)$
For other usage of virtualenvwrapper, refer to Documentation.
Recommended Posts