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.
--Not to mention a package management tool for Mac and Linux. This time it's all done.
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)
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
To uninstall Python 3 installed this time, execute it with the following command.
$ brew uninstall python
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