Mac OSX python多版本管理工具:pyenv 和 virtualenv搭建

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工程安装

  1. 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

  2. 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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值