mac M1 使用pyenv 安装python2.7踩坑记录

1,303 阅读1分钟

按照掘金上的文章使用HomeBrew安装虚拟环境构建Python2,(旧酒换新瓶,新版M1/M2芯片Macos(Ventura)安装古早版本Python2.7(Python2.x) - 掘金 (juejin.cn)) ,执行到最后一步,重新打开终端,执行 pyenv shell 2.7.18,并没有生效。 出现报错提示:

shell integration not enabled. Run `pyenv init' for instructions

终端执行 pyenv init 提示如下:

# Load pyenv automatically by appending 
# the following to  
~/.zprofile (for login shells) and ~/.zshrc (for interactive shells) :  
export PYENV_ROOT="$HOME/.pyenv" 
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" 
eval "$(pyenv init -)"  
# Restart your shell for the changes to take effect.

按照指示,分别打开.zprofile文件,.zshrc文件,找到文件的步骤如下: image.png 进入到个人文件夹后,快捷键:Command + Shift + . 显示隐藏的文件。可以看到.zprofile文件,.zshrc文件。 image.png 都在文件的最后加上提示中的内容:

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

保存文件,接着在终端执行:source ~/.zprofile 以及 source ~/.zshrc。 这时再在终端查看python,就会显示版本号了 image.png

常用命令指路

Mac上pyenv的安装与使用 - 掘金 (juejin.cn)