按照掘金上的文章使用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文件,找到文件的步骤如下:
进入到个人文件夹后,快捷键:Command + Shift + . 显示隐藏的文件。可以看到.zprofile文件,.zshrc文件。
都在文件的最后加上提示中的内容:
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
保存文件,接着在终端执行:source ~/.zprofile 以及 source ~/.zshrc。
这时再在终端查看python,就会显示版本号了