Python multi-version manager pyenv

View Linux version

1 [root@web ~]# cat /etc/redhat-release 
2 CentOS Linux release 7.6.1810 (Core) 
3 [root@web ~]# uname -a
4 Linux web 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

 

Installation pyenv

1 [root@web ~]# curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

 

Configuration environment variable

1 [root@web ~]# cd /root
2 [root@web ~]# cp .bash_profile .bash_profile.bak
3 [root@web ~]# vim .bash_profile
4 #pyenv
5 export PATH="~/.pyenv/bin:$PATH"
6 eval "$(pyenv init -)"
7 eval "$(pyenv virtualenv-init -)"
8 [root@web ~]# source .bash_profile

 

The system comes with python version 2.7.5

1 [root @ web ~] # python - V
 2 Python 2.7 . 5

 

Pyenv installed version 1.2.15

1 [root@web ~]# pyenv -v
2 pyenv 1.2.15

 

Upgrade pyenv command

1 [root@web ~]# pyenv update

 

View available python version which

1 [root@web ~]# pyenv install --list

 

Installation python3.6.4, python2.7.2 and python3.6.7

 

1 [root@web ~]# pyenv install 3.6.4
2 [root@web ~]# pyenv install 2.7.2
3 [root@web ~]# pyenv install 3.6.7

 

View installed python version which

1 [root@web ~]# pyenv versions
2 * system (set by /root/.pyenv/version)
3 2.7.2
4 3.6.4
5 3.6.7
6 [root@web ~]#

 

Enable the root user python version 3.6.4

[root@web ~]# cd /root/
[root@web ~]# pyenv virtualenv 3.6.4 root364
[root@web ~]# pyenv activate root364
[root@web ~]# pyenv global 3.6.4
(root364) [root@web ~]# python -V
Python 3.6.4

 

Currently used to remove virtualenv

(root364) [root@web ~]# pyenv deactivate
[root@web ~]#

 

To remove a virtualenv

1 [root@web ~]# pyenv virtualenv-delete root364
2 pyenv-virtualenv: remove /root/.pyenv/versions/3.6.4/envs/root364? y
3 [root@web ~]#

 

Set the / tmp directory pyenv environment python3.6.7

 1 [root@web ~]# cd /tmp/
 2 [root@web tmp]# pyenv virtualenv 3.6.7 tmp367
 3 Looking in links: /tmp/tmpshtqhsk6
 4 Requirement already satisfied: setuptools in /root/.pyenv/versions/3.6.7/envs/tmp367/lib/python3.6/site-packages (39.0.1)
 5 Requirement already satisfied: pip in /root/.pyenv/versions/3.6.7/envs/tmp367/lib/python3.6/site-packages (10.0.1)
 6 [root@web tmp]# pyenv activate tmp367
 7 [root@web tmp]# pyenv local tmp367 
 8 (tmp367) [root@web tmp]# python -V
 9 Python 3.6.7
10 (tmp367) [root@web tmp]# 
 
 

In the actual production environment, sometimes a machine above may require different Python environment to avoid upgrade or downgrade every time the system comes with Python version, so we use pyenv to manage different versions of Python, thereby improving efficiency.

Only needs to be installed on a single pyenv good service, you need to go download version of Python and the required dependencies, will go directly into the pyenv environment, bulk copy to another server, you can extract python version required for switching use, save a lot of grunt work time.

Guess you like

Origin www.cnblogs.com/bingo1024/p/12050721.html