対処前
% python --version
Python 2.7.16
対処方法
pyenv initを実行
% pyenv init
# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)
# Add pyenv executable to PATH and
# enable shims by adding the following
# to ~/.profile and ~/.zprofile:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
# Load pyenv into the shell by adding
# the following to ~/.zshrc:
eval "$(pyenv init -)"
# Make sure to restart your entire logon session
# for changes to profile files to take effect.
次にzprofileを開き、
% open ~/.zprofile
下記を記入
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
次にzshrc を開く
% open ~/.zshrc
下記を記入
eval "$(pyenv init -)"
次に下記を実行し、保存すると
% source ~/.zprofile
% source ~/.zshrc
改善された
% pyenv global 3.9.6
% python --version
Python 3.9.6
ただし、
% open ~/.zprofile
The file /Users/yuuki/.zprofile does not exist.
の場合
% echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
% echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
% echo 'eval "$(pyenv init -)"' >> ~/.zprofile