Detailed explanation of how pyenv manages multiple versions of python environments

黄舟
Release: 2017-10-19 10:53:49
Original
1418 people have browsed it

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 | bash
Copy after login

After 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 -)"
Copy after login

Then source the environment


$ .~/.bashrc
Copy after login

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)
Copy after login

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
...
Copy after login

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
...
Copy after login

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
Copy after login

Use the specified version of python


$ pyenv global 3.2.1
$ python -V
Python 3.2.1
Copy after login

View 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)
Copy after login

Use pyenv to manage virtualenv

Create a virtualenv environment

Use 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
Copy after login

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)
Copy after login

Remove the current need Used virtualenv


$ pyenv deactivate
Copy after login

Delete the current virtualenv that needs to be used


$ pyenv virtualenv-delete myenv
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!