pyenv 可以帮助你建立多个版本的 python 环境,它们相互隔离,不会污染到系统自带的 Python( pip 安装的包也是在各自目录下的)
pyenv 项目主页#安装步骤
$ brew update $ brew install pyenvPYENV_ROOT指向pyenv检出的根目录,并向$PATH添加$PYENV_ROOT/bin以提供访问pyenv这条命令的路径(这里的shell配置文件依不同SHELL而需作修改,如bash:~/.bash_profile,Zsh:~/.zshrc )
用 brew 安装的话,配置好环境变量的了(我自己又按手动方法在 zsh 里加了环境变量)
After installation, you’ll still need to add
eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"to your profile (as stated in the caveats). You’ll only ever have to do this once.
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. # 我的 zsh 将环境变量放在另一个文件(env.sh)中,在那里添加环境变量就可以了 $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc 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. # 使用自动完成功能,要将配置写在 shell configuration file 末尾 $ echo 'eval "$(pyenv init -)"' >> ~/.zshrc Restart your shell so the path changes take effect. $ exec $SHELL # 重启shell(因为修改了$PATH)pyenv-virtualenv 项目主页#安装步骤
使用 brew 安装
$ brew install pyenv-virtualenvAdd pyenv virtualenv-init to your shell to enable auto-activation of virtualenvs. This is entirely optional but pretty useful. See “Activate virtualenv” below.
# 使用自动完成等功能,直接将下面这句写在 shell configuration file (~/.zshrc) 末尾就可以 eval "$(pyenv virtualenv-init -)" # 用命令的话是下面那样: $ echo 'eval "$(pyenv init -)"' >> ~/.zshrc命令参考 · yyuu/pyenv
pyenv install安装指定的版本
$ pyenv install -v 2.7.13 #添加-v参数用于显示细节 $ pyenv rehash #安装新版本的python或者其他二进制包后都需要运行,或者重启shell创建虚拟环境–pyenv virtualenv 版本号 虚拟环境名。
$ pyenv virtualenv 3.5.1 venv-3.5.1You can also activate and deactivate a pyenv virtualenv manually:
pyenv activate <name> pyenv deactivatepython虚拟开发环境配置 - 简书 #配置好了 #相关使用可以再参考这个
Python多版本管理器pyenv和虚拟环境pyenv-virtualenv的安装设置 - 简书
使用pyenv搭建python虚拟环境 - 运维之美 | 十条
