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
1 [root@web ~]# curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
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
1 [root@web ~]# python -V 2 Python 2.7.5
1 [root@web ~]# pyenv -v 2 pyenv 1.2.15
1 [root@web ~]# pyenv update
1 [root@web ~]# pyenv install --list
1 [root@web ~]# pyenv install 3.6.4 2 [root@web ~]# pyenv install 2.7.2 3 [root@web ~]# pyenv install 3.6.7
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 ~]#
[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
(root364) [root@web ~]# pyenv deactivate
[root@web ~]#
1 [root@web ~]# pyenv virtualenv-delete root364 2 pyenv-virtualenv: remove /root/.pyenv/versions/3.6.4/envs/root364? y 3 [root@web ~]#
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]#
在实际的生产环境中,有时候一台机器上面可能需要不同的Python环境,避免每次都要升级或者降级系统自带的Python版本,所以我们使用pyenv来管理不同的Python版本,从而提高效率。
只需要在一台服务上安装好pyenv,再去下载好需要的Python版本和所需要的依赖库,将这个pyenv环境直接打包,批量拷贝到其他服务器,解压即可切换所需要的python版本使用,省去很多琐碎的工作时间。
原文:https://www.cnblogs.com/bingo1024/p/12050721.html