参考链接:
https://github.com/yyuu/pyenv-virtualenv
https://github.com/yyuu/pyenv
http://seisman.info/python-pyenv.html
http://www.it165.net/pro/html/201405/13603.html
1、 安装pyenv
$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ exec $SHELL -l
2、 安装pyenv-virtualenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile source ~/.bash_profile
3、安装依赖环境
sudo apt-get build-dep python2.
7
4、安装需要的python版本
pyenv install 2.7.11
5、创建需要的虚拟环境
pyenv virtualenv 2.7.11 venv2711
在这一步,我这里出现了一个异常: pyenv: no such command `sh-activate', 重启终端就可以了。
6、启动虚拟环境
pyenv activate venv2711
7、切换回系统环境
pyenv deactivate
在ubuntu16.04中出现错误: Build failed: "ERROR: The Python zlib extension was not compiled. Missing the zlib?", 解决办法:
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils