首先安装依赖
sudo apt-get install ruby build-essential libssl-dev libffi-dev libjpeg-dev libfreetype6-dev zlib1g-dev libreadline6 libreadline6-dev libsqlite-dev libsqlite3-dev libbz2-dev git -y
下载
sudo git clone git://github.com/yyuu/pyenv.git /usr/local/pyenv
添加环境变量 到/etc/profile
# /etc/profile
export PYENV_ROOT="/usr/local/pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
配置立即生效
. /etc/profile
安装指定版本
v=3.6.4
wget http://mirrors.sohu.com/python/$v/Python-$v.tar.xz -P /usr/local/pyenv/cache/;
pyenv install $v -v
如果提示缺少zlib则安装添加
sudo apt-get install ruby zlib1g zlib1g-dev -y
最后再次安装
pyenv install $v -v