git clone git://github.com/yyuu/pyenv.git ~/.pyenv
yum -y groupinstall "Development Tools"
yum -y install readline-devel zlib-devel bzip2-devel sqlite-devel openssl-devel
yum install readline readline-devel readline-static -y
yum install openssl openssl-devel openssl-static -y
yum install sqlite-devel -y
yum install bzip2-devel bzip2-libs -y
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >>~/.bash_profile
echo 'eval "$(pyenv init -)"' >>~/.bash_profile
source ~/.bash_profile
exec $SHELL -l
#安裝指定版本的python
pyenv install 3.5.4(如果下載下傳較慢,可以手動下載下傳Python-3.5.4.tar.xz安裝包上傳到/root/.pyenv/cache下,在執行這條指令)
版本切換
pyenv global 3.5.4
安裝virtualenv
pip install virtualenv
2種方法建立python3的虛拟環境
virtualenv /data/python/env3.5.4 --python=python3
virtualenv -p /root/.pyenv/versions/3.5.4/bin/python3 /data/python/env3.5.4
啟動虛拟環境
source /data/python/env3.5.4/bin/activate
退出虛拟環境
deactivate
原文連結:https://blog.csdn.net/abiao555/article/details/108170866