pyenv 是轻量的Python版本管理器,帮助你在一台机子上建立多个版本的python环境,并提供方便的切换方法。
pyenv-virtualenv 是 pyenv的扩展工具(类Unix系统上),可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解决包冲突问题。
更多pyenv和virtualenv的工作原理,请查看github工程说明。(引用1和2)
本文主要讲解Mac OSX上安装pyenv和virtualenv的过程,并记录安装中碰到的问题和相应的解决方法。
环境:OSX10.11 + shell: zsh + iTerm2
Installation pyenv
方法1:使用Mac OSX的Homebrew安装
$ brew update
$ brew install pyenv
方法2:通过github工程安装
Check out pyenv where you want it installed. A good place to choose is $HOME/.pyenv (but you can install it somewhere else).
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
Define environment variable PYENV_ROOT to point to the path where pyenv repo is cloned and add
$PYENV_ROOT/bin
to your$PATH
for access to the pyenv command-line utility.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile. Ubuntu note: Modify your ~/.bashrc file instead of ~/.bash_profile.
3. Add pyenv init to your shell to enable shims and autocompletion. Please make sure eval “$(pyenv init -)” is placed toward the end of the shell configuration file since it manipulates PATH during the initialization.
4. Restart your shell so the path changes take effect. You can now begin using pyenv.
$ $SHELL -l
或 $ exec $SHELL
5. Install Python versions into $PYENV_ROOT/versions
. For example, to download and insta