環境
- MacBook Pro (16-inch, 2019)
- macOS Monterey 12.3.1
- Xcode 13.3.1
- Homebrewインストール済み
- シェルはzsh
XcodeはApp Storeからダウンロードするだけです。
Homebrewは前に記事にしたのでどうぞ。

手順
Python3環境構築は、この動画が参考になるので貼っておきます。一応この動画と足りない部分はこの記事を参考にすればうまくいくと思います。
ちなみに僕の環境では、すでにPythonは入っていました。OSのMontereyに入っているのか、Xcodeを入れた時に入ったのかはわかりませんが…
Pythonが入っていない方は上記の動画を参考に入れてください。
Pythonのバージョン確認
ターミナルを起動し、以下のコードを入力して帰って来ればPythonが入っています。「V」は大文字なのでご注意を
$ python3 -V
Python 3.8.9
jupyterをインストール
jupyterをMacにいれます。すると、エラーが出てしまいました。
$ pip3 install jupyter
ERROR: Could not build wheels for argon2-cffi-bindings which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 20.2.3; however, version 22.1 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.
ERROR: Could not build wheels for argon2-cffi-bindings which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 20.2.3; however, version 22.1 is available.You should consider upgrading via the ‘/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install –upgrade pip’ command.
どうやら、こいつ「argon2-cffi-bindings」に問題があるようです。警告の方は、pipバージョンが古いから22.1にアップデートしろってことみたいです。
なので、pipをアップデートします。
pipをアップデート
cdでディレクトリを移動してからpipをアップデートします。
$ cd /Applications/Xcode.app/Contents/Developer/usr/bin/
$ python3 -m pip install --upgrade pip
Installing collected packages: pip
WARNING: The scripts pip, pip3, pip3.10 and pip3.8 are installed in '/Users/ユーザー名/Library/Python/3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.1
WARNING: You are using pip version 20.2.3; however, version 22.1 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.
なにやらまた、エラーが返ってきました。この一文が大事なところです。
WARNING: The scripts pip, pip3, pip3.10 and pip3.8 are installed in ‘/Users/ユーザー名/Library/Python/3.8/bin’ which is not on PATH.
要は、/Users/ユーザー名/Library/Python/3.8/binにPATHが通っていないから通せってことです。
ということでPATHを通しましょう。環境構築でつまづく原因の8割はPATH問題な気がする。。
Pythonのパスをマックに通す
ここで大事なのが、シェルが何かです。上の環境にある通り僕のシェルはzshを使ってます。大体、「zsh」か「bash」のどっちかです。シェルが何かわからない人はググりましょう。
「zsh」なら「.zshrc」、「bash」なら”.bash_profile”ファイルを開き、パスを追加します。ない場合touch .zshrc
でファイルを作ってください。
open ~/.zshrc
でファイルを開き、一番下に以下の内容を追記します。.zshrcファイルはuser直下にあるので直接開いても大丈夫です。Pythonが違うバージョンの人は適宜修正してください。
export PATH="$PATH:/Users/ユーザー名/Library/Python/3.8/bin"
最後にsource .zshrc
で編集した内容を反映させます。これ大事。
もう一度jupyter、jupyterlab をインストール
はい、というわけでもう一度JupyterとJupyterLabをインストールしましょう。ちなみにJupyterを入れるだけなら、pipをアップデートした段階でもできます。しかし、jupyter lab
実行時にエラーが出てくるので、先にパスを通しました。
$ pip3 install jupyter
$ pip3 install jupyterlab
警告は出たものの、エラーはなく入りました!
それと先ほどアップデートしたpipも確認しておきましょう。
$ pip3 -V
pip 22.1 from /Users/ユーザー名/Library/Python/3.8/lib/python/site-packages/pip (python 3.8)
無事、pip 22.1にアップデートされてました!
そして、JupyterLabを起動しましょう。
$ jupyter lab
[I 2022-05-17 16:39:12.471 ServerApp] jupyterlab | extension was successfully linked.
successfullyとなったのでOKです!!自動的にJupyterLabがブラウザで開かれ、Web上でPythonが使えるようになりました!
ということでお疲れ様でしたm(_ _)m