pyenvのバージョンをupdateする

背景・前提

最新のPythonを入れようとした際に、pyenvのエラーで入れることができなかった。

エラーメッセージ

$ pyenv install 3.10.4 python-build: definition not found: 3.10.4 See all available versions with 'pyenv install --list'. If the version you need is missing, try upgrading pyenv: cd /Users/{user名}/.pyenv/plugins/python-build/../.. && git pull && cd -

pyenvのversion

$ pyenv > pyenv 1.2.8-8-gf07184b3

インストールできるpackageの確認

$ pyenv install -list > Available versions: ...(省略) 3.7.0 3.7-dev 3.7.1 3.7.2 3.8-dev activepython-2.7.14 activepython-3.5.4 activepython-3.6.0 anaconda-1.4.0 ...(省略)

pyenvのバージョンが古すぎて、python3.10がないばかりか3.8すらdevバージョンである...macでPython触ってなかったからなぁ...

対応

pyenvをgit pullする

冒頭のエラーメッセージにもあった通り、pyenvのgitをpullする。

cd /Users/{user名}/.pyenv/plugins/python-build/../.. && git pull && cd -

ちなみにpathは以下のような感じで調べられる。

$ pyenv which python-build > /Users/{user名}/.pyenv/plugins/python-build/bin/python-build

git pullを実行すると以下のようにdiffが大量にでる。

libexec/pyenv-version | 4 +- libexec/pyenv-version-file-read | 2 +- libexec/pyenv-versions | 30 +- libexec/pyenv-which | 15 +- man/man1/pyenv.1 | 547 ++++++++++++++++++++ plugins/python-build/README.md | 58 ++- plugins/python-build/bin/pyenv-install | 6 +- plugins/python-build/bin/pyenv-uninstall | 5 +- plugins/python-build/bin/python-build | 685 ++++++++++++++------------ plugins/python-build/scripts/README.md | 22 + plugins/python-build/scripts/add_miniconda.py | 332 +++++++++++++ plugins/python-build/scripts/requirements.txt | 1 + plugins/python-build/share/python-build/2.1.3 | 4 +- plugins/python-build/share/python-build/2.2.3 | 4 +- plugins/python-build/share/python-build/2.3.7 | 4 +- plugins/python-build/share/python-build/{2.4 => 2.4.0} | 4 +- plugins/python-build/share/python-build/2.4.1 | 4 +- plugins/python-build/share/python-build/2.4.2 | 4 +- plugins/python-build/share/python-build/2.4.3 | 4 +- plugins/python-build/share/python-build/2.4.4 | 4 +- plugins/python-build/share/python-build/2.4.5 | 4 +- plugins/python-build/share/python-build/2.4.6 | 4 +-

バージョン確認

$ pyenv > pyenv 2.3.0-1-g867f34b5

1.2から2.3にバージョンが上がったことがわかる。

最新のpythonをinstall

$ pyenv install 3.10.4 > python-build: use openssl@1.1 from homebrew python-build: use readline from homebrew Downloading Python-3.10.4.tar.xz... -> https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tar.xz Installing Python-3.10.4... python-build: use readline from homebrew python-build: use zlib from xcode sdk Installed Python-3.10.4 to /Users/{user名}/.pyenv/versions/3.10.4
$ pyenv versions * 3.10.4 (set by /Users/xxx/.python-version) 3.6.6 3.7.2 anaconda3-5.3.1

入った。