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.
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.
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.
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
With a recent Homebrew update, python
Formula 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