Appleシリコン搭載のMacに python3 をインストール

Appleシリコン搭載のMacへのpython3インストール方法とpip3の簡単な使用について紹介する。

筆者の環境
Mac mini (M1, 2020)
OS Big Sur (バージョン 11.2.2)


ここでは次の手順で説明する。

  1. はじめに
  2. Python3 のインストール
  3. pip3 の使用

はじめに

M1チップ搭載のMac購入時、python3 は未インストールだった。

pythonコマンドの結果

user@hogenoMac-mini ~ % python 

WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Oct 18 2020, 18:43:19) 
[GCC Apple LLVM 12.0.0 (clang-1200.0.30.4) [+internal-os, ptrauth-isa=sign+stri on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ]

python3の使用を推奨するとある。

python3 のインストール

python3 コマンドを実行

user@hogenoMac-mini ~ % python3
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

developer tools が見つからないとメッセージが出て、下記ダイアログが表示される。

「インストール」をクリックすると使用許諾が表示される。確認して同意するとインストールが開始され、python3 コマンドが使用できるようになった。

pip3のインストールについては こちらの「macOS Big Sur の Python」を参考にさせていただきました。

pip3 の使用

インストール済みのモジュールを確認する。

user@hogenoMac-mini ~ % pip3 list
Package    Version
---------- -------
pip        19.2.3 
setuptools 41.2.0 
six        1.15.0 
wheel      0.33.1 
WARNING: You are using pip version 19.2.3, however version 20.3.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
user@hogenoMac-mini ~ % 

ここで pip をアップグレードするようWARNINGがあったため、下記のようにアップグレードを実施。

user@hogenoMac-mini ~ % pip3 install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/54/eb/4a3642e971f404d69d4f6fa3885559d67562801b99d7592487f1ecc4e017/pip-20.3.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 'RECORD'
Consider using the `--user` option or check the permissions.

WARNING: You are using pip version 19.2.3, however version 20.3.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Permission denied が発生したため、sudo で実行する。

user@hogenoMac-mini ~ % 
sudo pip3 install --upgrade pip
Password:(ここでパスワードを入力する)
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/eb/4a3642e971f404d69d4f6fa3885559d67562801b99d7592487f1ecc4e017/pip-20.3.3-py2.py3-none-any.whl (1.5MB)
     |████████████████████████████████| 1.5MB 5.5MB/s 
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-20.3.3

この後pip3を用いてモジュールを追加する際、numpy などはターミナルでRosettaを使用する必要がある。

以上

スポンサーリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする