0
2

More than 3 years have passed since last update.

pyenvでPythonのバージョンを切り替えられない場合の対処法

Posted at

対処前

 % 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
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2