xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)

MacOS Catalina にアップデートした後にPythonのバージョンを上げようとしたところ、以降のようなエラーが発生しました。

~ $ pyenv install 3.8.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.1.tar.xz...
-> https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
Installing Python-3.8.1...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.15.3 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/hh/zc50ylq92gb27pqz3r_1390c23xhm3/T/python-build.20200321165805.8795
Results logged to /var/folders/hh/zc50ylq92gb27pqz3r_1390c23xhm3/T/python-build.20200321165805.8795.log

Last 10 log lines:
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "darwin"
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/hh/zc50ylq92gb27pqz3r_1390c23xhm3/T/python-build.20200321165805.8795/Python-3.8.1':
configure: error: C compiler cannot create executables
See `config.log' for more details
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun



xcodeを入れると解決するとのことで、こちらのコマンドを実行。(GUIのダイアログボックスが出る)

~ $ xcode-select --install
xcode-select: note: install requested for command line developer tools

無事にPythonのバージョンアップができました。