LoginSignup
0
2

More than 3 years have passed since last update.

Pythonのバージョンが2から3に変わらない現象【体験談】

Posted at

エンジニア歴2年のkitagawaです。

Pythonを触り始めて、バージョンが変わらない現象が起きました。
調べてみてたくさん記事が出てきましたが、手っ取り早くバージョンアップできる方法を忘備録として記載します。

% python -V      
Python 2.7.16

と表示されてしまいます。

そこで、~/.bash_profileの内容を変更し反映させれば、最新のバージョンになります。

vi ~/.bash_profile
~/.bash_profile
export PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

上記が記入できたらESC押下し、:wqと入力で保存して終了。(:qaだと保存せず終了)

source ~/.bash_profileをし反映させると、Pythonのバージョンが変わっていることが確認できます。

% source ~/.bash_profile
% python -V             
Python 3.9.4

ちなみに原因はわからないのですが、再起動してしまうとバージョンが戻ってしまうので、私はいつもsourceで反映させてからバージョンアップしています(謎)

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