Use Python 3 introduced with command line tools on macOS Catalina

Introduction

You can easily use Python 2.7 and Python 3.7 by installing the command line tools on macOS Catalina.

You can install the command line tools with xcode-select --install. Please refer to the following.

Until now, I think that there were many people who installed Python3 using the official package to use it on macOS, or installed and used Python3 with Homebrew.

Problems occur

I got a question mark that I couldn't execute the command that should have been installed by Python package manager (pip3) in Python 3 that I recently installed with Homebrew, but I found the cause.

Probably, when I installed Formula that requires Python 3.8 with Homebrew, Python 3.8 was installed at the same time, but I think it was because I did not pass the path of Python 3.8.

pip3とpython3バージョンの不一致

It seems that pip etc. can be replaced by installing Python with Homebrew. It was organized in this document. Then I think that the Python3 command will be replaced, but I wonder if it was registered halfway.

As a result, the version mismatch between the pip3 command and the python3 command occurred, and it seems that the state was "Are there any packages installed with pip3?" .. This condition is not good. You need to go through the Python 3.8 path or configure it to use Python 3.7.

Kuu! !! ... stop putting Python 3 in Homebrew anymore.

This time I decided to use Python 3 from macOS Catalina instead of Python 3 from Homebrew. The procedure is as follows.

Solution

For the time being, I dealt with it as follows.

$ brew uninstall [email protected]
Error: Refusing to uninstall /usr/local/Cellar/[email protected]/3.8.5
because it is required by ansible and openstackclient, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies [email protected]

Since Python 3.8 cannot be deleted because there is a Formula that depends on the previous step, delete the Formula that was in the error message.

$ brew uninstall ansible openstackclient
$ brew uninstall [email protected]
$ python3 --version
Python 3.7.3
$ pip3 --version
pip 19.0.3 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

Using --user will extract binaries etc. to the user's bin directory. Use --user because it doesn't affect other users or the system.

$ pip3 install --user ansible
$ pip3 install --user python-openstackclient

I forgot to write it, but from Catalina the standard shell is zsh (I'm using zsh from Mojave). The following is an example of setting zsh. If you are using another shell, find out how to pass it in that shell (for bash, write it in .bashrc).

$ vi ~/.zshrc
export PATH="/Users/username/Library/Python/3.7/bin:/usr/local/bin:/usr/local/sbin:$PATH"
$ ansible --version
ansible 2.9.11
  config file = None
  configured module search path = ['/Users/ytooyama/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/ytooyama/Library/Python/3.7/lib/python/site-packages/ansible
  executable location = /Users/ytooyama/Library/Python/3.7/bin/ansible
  python version = 3.7.3 (default, Mar  6 2020, 22:34:30) [Clang 11.0.3 (clang-1103.0.32.29)]
$ openstack --version
openstack 5.3.1

Remarks

With a recent Homebrew update, pythonFormula now points to Python 3.8 (formerly Python 2). If you need Python 3.7, you need to install python @ 3.7. It's a little troublesome when the version changes.

Recommended Posts

Use Python 3 introduced with command line tools on macOS Catalina
Install Python 3 on MacOS Catalina (with Homebrew only)
How to use python put in pyenv on macOS with PyCall
Install Python less than 3.5.3 on macOS Catalina
Installing PIL with Python 3.x on macOS
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
After updating to MacOS Catalina, install Xcode Command Line Tools and change from Python 2.7 series to 3.7 series (bash)
My thoughts on python2.6 command line app template
Get started with Python on macOS Big Sur
Until you use PhantomJS with Python on Heroku
Install Python and libraries for Python on MacOS Catalina
Use mecab with Python3
Use DynamoDB with Python
Use Python 3.8 with Anaconda
Use python with docker
Notes on creating a python development environment on macOS Catalina
Yum command to access MySQL with Python 3 on Linux
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Steps to use the AWS command line interface (Python / awscli) on Mac OS X
Use Trello API with python
Use matplotlib on Ubuntu 12 & Python
ArcPy-Introduction to Geoprocessing with Python with Scripting Tools on ArcGIS Pro-
Use Twitter API with Python
Use TUN / TAP with Python
Made python available on macOS
IP spoof using tor on macOS and check with python
Run unix command on python
Use subsonic API with python3
Broadcast on LINE using python
Use Python on Windows (PyCharm)
Run OpenVino on macOS Catalina
Create another version of Python conda environment with one command line
A note on what you did to use Flycheck with Python
Does CoreML Tools + macOS High Sierra work only with apple python?
Error and solution when installing python3 with homebrew on mac (catalina 10.15)
Python standard module that can be used on the command line
How to use Python with Jw_cad (Part 2 Command explanation and operation)
Command line argument processing (Python docopt)
Python: How to use async with
Use PointGrey camera with Python (PyCapture2)
Use vl53l0x with Raspberry Pi (python)
Slice notation with command line options
Get started with MicroPython (on macOS)
Print with python3 without line breaks
[Python] Use Basic/Digest authentication with Flask
Use NAIF SPICE TOOLKIT with Python
Use rospy with virtualenv in Python3
Python development environment construction on macOS
Use Python in pyenv with NeoVim
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
How to use FTP with Python
Use Windows 10 speech synthesis with Python
Notes on using rstrip with python.
Use OpenCV with Python 3 in Window
Getting started with Python 3.8 on Windows
Sakura Use Python on the Internet
Use PostgreSQL with Lambda (Python + psycopg2)
Install python2.x on catalina with pyenv
Use gcc-4.2 when compiling Python (MacOS)
[Python] Make pip available on macOS
[Memo] Tweet on twitter with python