Notes on building Python and pyenv on Mac

Here's a quick summary of how to install Python on your Mac and manage it with pyenv. For busy people.

Install Python and pyenv

#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   

When pyenv does not switch versions

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)

Summary

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

Notes on building Python and pyenv on Mac
Notes on pyenv and Atom
Notes on installing Python on Mac
Catalina on Mac and pyenv
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Notes on Python and dictionary types
Notes on installing Python using PyEnv
(Beginner) Notes on using pyenv on Mac
python on mac
Notes on deploying pyenv with Homebrew and managing Python versions
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install pyenv on mac
Install Python 3 on Mac
Install Python 3.4 on Mac
Notes on installing Python3 and using pip on Windows7
Put Python 2.7.x on Mac OSX 10.15.5 with pyenv
Remove old pyenv environment on Mac and update
Try importing MLB data on Mac and Python
Try to build python and anaconda environment on Mac (by pyenv, conda)
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Install Python3 on Mac and build environment [Definitive Edition]
Python on Ruby and angry Ruby on Python
Notes on installing dlib on mac
Notes on HDR and RAW image processing with Python
Install selenium on Mac and try it with python
[Python] Notes on data analysis
Handling of python on mac
Update python on Mac to 3.7-> 3.8
Install pandas 0.14 on python3.4 [on Mac]
Build a Python environment on your Mac using pyenv
Installing Python 3 on Mac and checking basic operation Part 1
Pyenv on Mac OSX Mavericks
python with pyenv and venv
Notes on installing pipenv on Mac
Install pyenv on Raspberry Pi and version control Python
Install Python environment on local PC (pyenv, venv on Mac)
Minimum memo when using Python on Mac (pyenv edition)
Notes on installing Python on CentOS
Minimum notes when using Python on Mac (Homebrew edition)
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Notes on building TinyEMU and booting the Linux kernel on Emscripten
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
[Python] Notes on while statements (writing style and infinite loop)
Until building a Python development environment using pyenv on Ubuntu 20.04
Notes on reading and writing float32 TIFF images in python
If python on mac goes missing
Python 3.6 on Windows ... and to Xamarin.
MQTT on Raspberry Pi and Mac
Error when building mac python environment
Building a Python environment on Ubuntu
Introducing Python using pyenv on Ubuntu 20.04
Notes on using MeCab from Python
Create a Python environment on Mac (2017/4)
Survey on building and running kivi
Notes on using post-receive and post-merge
Python environment construction memo on Mac
Install Python 3.7 Anaconda on MAC, but Python 2
Install python3 on Mac (El Capitan)
Integrate Modelica and Python on Windows
Environment construction of python3.8 on mac
Notes on using rstrip with python.