LoginSignup
45
24

More than 3 years have passed since last update.

pyenv globalでpythonのバージョンが切り替わらない(mac)

Posted at

pythonの環境設定をこちらの記事に沿って進めていきました。

macではデフォルトでpythonがインストールされていますが、2系の古いバージョンであるため、こちらを使わず使わず新たにインストールしていきます。
ここで、pythonのバージョン管理ツールpyenvを使用してインストールしていきます。
記事通りの内容は割愛しています。

zsh
.....

% pyenv global 3.9.5

% python --version
Python 2.7.16

...切り替わらない

ググると eval "$(pyenv init -)" をやれと書いてある。
早速実行

zsh
 % eval "$(pyenv init -)" 
WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.

ここでエラーが発生
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.

記事の方では echo 'export ~'とやっていたが。。
echoなしで、もう一度設定をやり直す必要があるようだ。

実行

zsh
% export PYENV_ROOT="$HOME/.pyenv"
% export PATH="$PYENV_ROOT/bin:$PATH"
% eval "$(pyenv init --path)"
% eval "$(pyenv init -)"
% pyenv global 3.9.5   
% python --version  
Python 3.9.5

切り替えに成功

今後なぜechoコマンドでの設定が成功しなかった理由を調べます。

45
24
5

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
45
24