Here's a quick summary of how to install Python on your Mac and manage it with pyenv. For busy people.
#Install Homebrew and pyenv
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
# /Users/user/.From pyenv/usr/local/var/Settings to change to pyenv
cat << 'EOS' >> ~/.zshrc
# ↓↓↓ heredoc>
export PYENV_ROOT=/usr/local/var/pyenv
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
EOS
# ↑↑↑ heredoc>
#Reload
zsh -l
#Python installation
pyenv install 3.8.2
pyenv global 3.8.2
#Verification
python -V
3.8.2
pyenv version
3.8.2 (set by /usr/local/var/pyenv/version)
#When you want to change the version
pyenv install 3.6.5
pyenv global 3.6.5
python -V
Failure example
pyenv versions
system
* 3.6.5 (set by /Users/koji4104/.python-version)
3.8.2
Success story
pyenv versions
system
3.6.5
* 3.8.2 (set by /usr/local/var/pyenv/version)
The cause seems to have been built locally in the past. In the Finder, delete the .python-version file directly under the user (hidden file)
I've summarized the steps to build Python and pyenv. I had a little trouble when I tried to run Python on my new Mac. There is a detailed explanation site, but I couldn't find a site that summarizes it briefly, so I wrote it as an article.
Recommended Posts