Install Python 3 on MacOS Catalina (with Homebrew only)

Introduction

This article summarized how to install Python3 using pyenv. There was also a way to install it only with Homebrew without using pyenv, so I tried it as a study.

Execution environment

Package to use

--Not to mention a package management tool for Mac and Linux. This time it's all done.

Installation flow

  1. [Install Homebrew](# 1 Install homebrew)
  2. [Install Python](# 2 Install python)

1. Install Homebrew

Execute the following command in the terminal according to the official documentation. If it is already installed, you can skip it.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

If the installation is successful, you can check the Homebrew version with the brew -v command.

$ brew -v
Homebrew 2.4.9
Homebrew/homebrew-core (git revision 3b87b; last commit 2020-08-04)
Homebrew/homebrew-cask (git revision 2ee9f; last commit 2020-08-04)

2. Install Python

Update Homebrew to the latest version before installing. Update to the latest state with the brew command.

$ brew update

After Homebrew is updated, install Python3 with brew install.

$ brew install python

You can check the installed packages with brew list.

$ brew list
etc...
[email protected]
etc...

This completes the Python3 installation, but the system still recognizes Python2 by default.

Therefore, the python and pip commands are executed in Python2, so you must enter python3 and pip3 to execute Python3 before they are recognized.

$ python -V
Python 2.7.16

$ python3 -V
Python 3.8.5


$ pip -V
zsh: command not found: pip

$ pip3 -V
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

Well, it works, so it's okay to say that, but it's troublesome, so put it in the PATH.

Check the directory where Python3 is installed with the brew info command.

$ brew info python
[email protected]: stable 3.8.5 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/[email protected]/3.8.5 (4,339 files, 67.3MB) *
  Poured from bottle on 2020-08-05 at 17:48:14
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]
License: Python-2.0
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, [email protected] ✔, readline ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/[email protected]/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.8/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 749,693 (30 days), 1,531,213 (90 days), 2,458,114 (365 days)
install-on-request: 200,840 (30 days), 225,547 (90 days), 257,646 (365 days)
build-error: 0 (30 days)

It will be displayed in various ways, but what you need this time is the one displayed at the bottom,

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/[email protected]/libexec/bin

Only the part of. It turns out that the related packages that were actually installed with Python 3 were installed in / usr / local / opt / [email protected] / libexec / bin. So add this to your PATH in the terminal.

$ echo "export PATH=/usr/local/opt/[email protected]/libexec/bin" >> ~/.zshrc
$ source .zshrc

Click here if the terminal is bash.

$ echo "export PATH=/usr/local/opt/[email protected]/libexec/bin" >> ~/.bash_profile
$ source .bash_profile

If you want to edit the profile etc. directly with vim, please add the following contents.

export PATH=/usr/local/opt/[email protected]/libexec/bin

Python3 works with python and pip respectively.

$ python -V
Python 3.8.5

$ pip -V
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

It also works by setting an alias instead of going through the PATH. I think PATH is better.

$ echo "alias python=python3" >> .zshrc
$ echo "alias pip=pip3" >> .zshrc
$ source .zshrc

bonus

To uninstall Python 3 installed this time, execute it with the following command.

$ brew uninstall python

Afterword

It's easier than using pyenv. However, you have to go through the PATH, and as far as you can see, it seems to change every time the version of Python 3 changes, so I have a feeling that it will be necessary to reset the PATH every time Python 3 is updated.

If you just want to try it out before full-scale development, you may install it this way, but I think you should stop using Python3 installed this way for development.

Recommended Posts

Install Python 3 on MacOS Catalina (with Homebrew only)
Install Python less than 3.5.3 on macOS Catalina
Install Python and libraries for Python on MacOS Catalina
Install python2.x on catalina with pyenv
Use Python 3 introduced with command line tools on macOS Catalina
scipy stumbles with pip install on python 2.7.8
Installing PIL with Python 3.x on macOS
Install python on WSL
Install Python on Pidora.
Install Scrapy on python3
[Ansible] Install dnf on Centos7 with Python3 interpreter
Install Python 3.8.6 on macOS Big Sur using pyenv
Install Python on Mac
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Install Python 3 on Mac
I wanted to install Python 3.4.3 with Homebrew + pyenv
Install Python3.4 on CentOS 6.6
Install Voluptuous with Python 2.5
Install python on windows
Run pip install on MacOS Python 3.7 or later
Install Python 2.7.3 on CentOS 5.4
Install python with pyenv
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Install Python 3.6 on Docker
Install selenium on Mac and try it with python
Notes on creating a python development environment on macOS Catalina
Install PyQt5 with homebrew on Mac OS X Marvericks (10.9.2)
Install the latest Python from pyenv installed with homebrew
Install Python 3.8 on RHEL 8 (AppStream)
Install watchdog on Windows + Python 3.3
Install pygame on python3.4 on mac
Install Python 3.8 on CentOS 7 (SCL)
Made python available on macOS
Install OpenPose on mac (Catalina)
Install external libraries with Python
Python --Install MySQLDB on EC2
Install pyenv from Homebrew, install Python from pyenv
Install Python 3.8 on CentOS 8 (AppStream)
Install Homebrew on Amazon Linux 2
[Python] [Chainer] [Windows] Install Chainer on Windows
Run OpenVino on macOS Catalina
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
IP spoof using tor on macOS and check with python
Notes on deploying pyenv with Homebrew and managing Python versions
How to install Theano on Mac OS X with homebrew
Install Python Pillow on Amazon Linux
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Python 2.7.9 and Python 3.4.x with pip.
Setup modern Python environment with Homebrew
I can't install python3 with pyenv-vertualenv
HomeBrew can't install Python (at Mavericks)
Install Python from source with Ansible
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install python2.7 on windows 32bit environment
Get started with MicroPython (on macOS)
Install xgboost (python version) on Windows
Install Python on Windows + pip + virtualenv
Introducing OpenCV on Mac with homebrew
Install Pytorch on Blender 2.90 python on Windows
Install Python 3.7 Anaconda on MAC, but Python 2