Made python available on macOS

background

I wanted to use python on macOS Big Sur. (I wanted to use a command called CuteR: I made a QR code image with CuteR)

However, when using pip

$ pip install
dyld: Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
  Reason: image not found
Abort trap: 6

Will be.

Same with $ python3.

Basic direction

Python in macOS environment: https://www.python.jp/install/macos/index.html

according to

--Don't try to use the python that comes with macOS --Install with Homebrew --Use python3.9 -m pip xxx instead of pip3 --Run in a virtual environment such as venv

That's right. Here, I tried up to the above three.

Work log

When you do $ brew update, you will first reach out to dogit --C ....

$ brew update
Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow

First, fetch and then $ brew update

$ git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
remote: Enumerating objects: 690418, done.
remote: Counting objects: 100% (690359/690359), done.
remote: Compressing objects: 100% (233146/233146), done.
remote: Total 680792 (delta 450632), reused 674814 (delta 444788), pack-reused 
Receiving objects: 100% (680792/680792), 271.20 MiB | 14.34 MiB/s, done.
Resolving deltas: 100% (450632/450632), completed with 7510 local objects.
From https://github.com/Homebrew/homebrew-core
   baf6aab591..b293a33dd8 master     -> origin/master

$ brew update

Install python.

$ brew install python
Warning: [email protected] 3.9.1_3 is already installed, it's just not linked
You can use `brew link [email protected]` to link this version.

It seems that it is included. You just have to link.

$ brew link [email protected]
Linking /usr/local/Cellar/[email protected]/3.9.1_3... 
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

Hmmm, rm and brew link.

$ rm '/usr/local/bin/2to3'
$ brew link --overwrite [email protected]
Linking /usr/local/Cellar/[email protected]/3.9.1_3... 25 symlinks created

I did this

$ pip install 
$ python3

Then, the same error as at the beginning. Instead

$ python3.9
Python 3.9.1 (default, Dec 28 2020, 11:25:16) 
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

I got it! So, try pip by referring to the following site. https://www.python.jp/install/macos/pip.html

$ python3.9 -m pip install pillow
Collecting pillow
  Downloading Pillow-8.0.1-cp39-cp39-macosx_10_10_x86_64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 3.7 MB/s 
Installing collected packages: pillow
Successfully installed pillow-8.0.1
WARNING: You are using pip version 20.3.1; however, version 20.3.3 is available.
You should consider upgrading via the '/usr/local/opt/[email protected]/bin/python3.9 -m pip install --upgrade pip' command.

It is said that you are willing to do so.

$ python3.9 -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (20.3.1)
Collecting pip
  Downloading pip-20.3.3-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 6.2 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.3.1
    Uninstalling pip-20.3.1:
      Successfully uninstalled pip-20.3.1
Successfully installed pip-20.3.3

According to the above site, once pillow is uninstalled

$ python3.9 -m pip uninstall pillow
Found existing installation: Pillow 8.0.1
Uninstalling Pillow-8.0.1:
  Would remove:
    /usr/local/lib/python3.9/site-packages/PIL/*
    /usr/local/lib/python3.9/site-packages/Pillow-8.0.1.dist-info/*
Proceed (y/n)? y
  Successfully uninstalled Pillow-8.0.1

This is fine.

Impressions

――It was insanely simple and refreshing to say "I don't use the python included in macOS ". ――I didn't write it here, but "using venv "was simple and very refreshing. --Refer to "Creating a QR code image with CuteR" for a usage example. ――Once upon a time, what about pyenv, so I have a messy memory.

resource

Python in macOS environment: https://www.python.jp/install/macos/index.html Python in macOS environment --pip: https://www.python.jp/install/macos/pip.html

Almost written in ↑. This article is, so to speak, "Tsukurepo".

environment

Python 3.9.1 (Dec 28 2020, 11:25:16) macOS BigSur version 11.1 MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)

Recommended Posts

Made python available on macOS
[Python] Make pip available on macOS
Python development environment construction on macOS
Python on Windows
twitter on python3
Build a python environment on MacOS (Catallina)
python on mac
Install Python less than 3.5.3 on macOS Catalina
Python on Windbg
Installing PIL with Python 3.x on macOS
Python installation 2020 (macOS)
Install Python 3.8.6 on macOS Big Sur using pyenv
Run pip install on MacOS Python 3.7 or later
Make DHT11 available on Raspberry Pi + python (memo)
Get started with Python on macOS Big Sur
Install Python 3 on MacOS Catalina (with Homebrew only)
Install Python and libraries for Python on MacOS Catalina
Python conda on cygwin
Install python on WSL
PyOpenGL setup on Python 3
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
Install Python 3 on Mac
Install Python3.4 on CentOS 6.6
Installing pandas on python2.6
python basic on windows ②
Install python on windows
Install Python 2.7.3 on CentOS 5.4
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Install Python 3.6 on Docker
Notes on creating a python development environment on macOS Catalina
I made a Python3 environment on Ubuntu with direnv.
Build a Python development environment using pyenv on MacOS
Set-enable Python virtualenv on Windows
Set up Python 3.4 on Ubuntu
Build a python machine learning study environment on macOS sierra
Run Openpose on Python (Windows)
Install Python 3.8 on RHEL 8 (AppStream)
Install watchdog on Windows + Python 3.3
Python on Ruby and angry Ruby on Python
Make iPython available on OSGeo4W
Install pygame on python3.4 on mac
Use Python 3 introduced with command line tools on macOS Catalina
I made blackjack with python!
Python + Kivy development on Windows
Install Python 3.8 on CentOS 7 (SCL)
OpenCV3 installation for Python3 @macOS
Real-time graphs on Plotly (Python)
Memo of python + numpy/scipy/pandas/matplotlib/jupyterlab environment construction on M1 macOS (as of 2020/12/24)
IP spoof using tor on macOS and check with python
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Put Python 3.x on Ubuntu
Make Cython available on Windows.
Fastest Python installation on Windows
[Python] Notes on data analysis
Build Python environment on Windows
Run Tensorflow 2.x on Python 3.7
Handling of python on mac