mac 下安装pyenv


1、安装pyenv

brew  install pyenv

2、添加环境变量PYENV_ROOT

# 修改 ~/.bash_profile  添加
export PYENV_ROOT=/usr/local/var/pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

3、安装 python

pyenv install 3.6.2

如果上面安装很慢可以将文件包下载下来,放到 $PYENV_ROOT/cache 目录中(提前创建好)

mkdir -p $PYENV_ROOT/cache
cd $PYENV_ROOT/cache
wget https://tool-box.oss-cn-hangzhou.aliyuncs.com/Python-3.6.2.tar.xz
pyenv install 3.6.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.6.2...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.6.2 to /usr/local/var/pyenv/versions/3.6.2

4、安装pyenv-virtualenv

brew install pyenv-virtualenv
#  修改 ~/.bash_profile  添加
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
 source ~/.bash_profile

5、使用

pyenv virtualenv 3.6.2 env362
pyenv activate env362
mac@1987demac ~ % pyenv activate env362
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(env362) mac@1987demac ~ % python
Python 3.6.2 (default, Aug 19 2020, 14:33:39) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>