Home >Backend Development >Python Tutorial >Detailed explanation of how pyenv manages multiple versions of python environments
This article mainly introduces the detailed explanation of using pyenv to manage multiple versions of python environment. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
As more and more projects are developed at the same time, we need to constantly switch between different versions of python environments, so I thought of pyenv. The virtualenv that has been used in the past can only manage the versions of third-party libraries under the same python version, but for cases that require switching between multiple different versions, pyenv can only be used.
Installation
Run the following command to automatically download and install
##
$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bashAfter the installation is completed, you need to modify it~ /.bashrc file, add pyenv to PATH. Here is to add the following lines to the ~/.bashrc file.
export PATH="/home/kongxx/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"Then source the environment
$ .~/.bashrc
Use pyenv to manage the python version
First check the python version installed and in use on the current system.$ pyenv versions * system (set by /home/kongxx/.pyenv/version)The system indicates the package installed by the system. * indicates the python environment currently being used. View the python versions that can currently be installed.
$ pyenv install -l Available versions: 2.1.3 2.2.3 2.3.7 2.4 2.4.1 ...
Install the specified version of python
$ pyenv install 2.7.10 Downloading Python-2.7.10.tar.xz... -> https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz Installing Python-2.7.10... patching file ./Lib/site.py Installed Python-2.7.10 to /home/kongxx/.pyenv/versions/2.7.10 $ pyenv install 3.2.1 ...After installation, check that it is now installed python version.
$ pyenv versions * system (set by /home/kongxx/.pyenv/version) 2.7.10 3.2.1
Use the specified version of python
$ pyenv global 3.2.1 $ python -V Python 3.2.1View the currently used python after use Version.
$ pyenv version 3.2.1 (set by /home/kongxx/.pyenv/version) $ pyenv versions system 2.7.10 * 3.2.1 (set by /home/kongxx/.pyenv/version)
Use pyenv to manage virtualenv
Create a virtualenv environmentUse python 3.2.1 to create it here A virtualenv environment$ pyenv virtualenv 3.2.1 myenv $ pyenv versions system 2.7.10 * 3.2.1 (set by /home/kongxx/.pyenv/version) 3.2.1/envs/myenv myenv
Activate the virtualenv that currently needs to be used
$ pyenv activate myenv $ pyenv versions system 2.7.10 3.2.1 3.2.1/envs/myenv * myenv (set by PYENV_VERSION environment variable)Remove the current need Used virtualenv
$ pyenv deactivateDelete the current virtualenv that needs to be used
$ pyenv virtualenv-delete myenv
The above is the detailed content of Detailed explanation of how pyenv manages multiple versions of python environments. For more information, please follow other related articles on the PHP Chinese website!