运行环境
系统版本:CentOS Linux release 7.6.1810 (Core)
软件版本:无
硬件要求:无
安装过程
1、安装依赖
[root@localhost ~]# yum -y install git gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel
2、从Git存储库中克隆Pyenv
[root@localhost ~]# git clone https://github.com/pyenv/pyenv.git ~/.pyenv
3、配置环境变量
[root@localhost ~]# vim /etc/profile
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH=$HOME/.pyenv/bin:$PATH
eval "$(pyenv init -)"
[root@localhost ~]# source /etc/profile
4、查看Pyenv版本
[root@localhost ~]# pyenv -v
pyenv 1.2.18
5、查看可安装的Python版本
[root@localhost ~]# pyenv install --list
6、修改Python安装包下载源为淘宝(永久性修改)
[root@localhost ~]# for i in $(grep -r 'www.python.org' ~/.pyenv/*|awk -F ':' '{print $1}'|grep '^/');do sed -i 's#https://www.python.org/ftp/#https://npm.taobao.org/mirrors/#g' $i;done
7、安装指定版本的Python
[root@localhost ~]# pyenv install 3.6.9
8、修改下载源为淘宝并安装指定版本的Python(临时性修改)
[root@localhost ~]# v=3.6.9;wget https://npm.taobao.org/mirrors/python/$v/Python-$v.tar.xz -P ~/.pyenv/cache/;pyenv install $v
9、查看Pyenv托管的Python版本列表
[root@localhost ~]# pyenv versions
* system (set by /root/.pyenv/version)
3.6.9
10、切换系统中的Python环境到指定版本
[root@localhost ~]# pyenv global 3.6.9
[root@localhost ~]# python
Python 3.6.9 (default, Apr 9 2020, 07:01:31)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
11、卸载指定版本的Python
[root@localhost ~]# pyenv uninstall 3.8.0
pyenv: remove /root/.pyenv/versions/3.8.0? yes
[root@localhost ~]# pyenv versions
system
* 3.6.9 (set by /root/.pyenv/version)