今回はターミナルを使った方法で実行する。
まずは、pythonがインストールされていないことを確認する。
python --version
あるいは
python3 --version
インストールされていないと以下の表示になる。
bash: python: command not found
Macのpythonインストールには、Homebrewが必要。
Homebrewは、macOS(またはLinux)用パッケージマネージャーです。
Homebrewがインストールされているかは以下で確認します。
brew -v
Homebrewについてわからないことはこちらを確認します。
pythonをインストールする。
brew install python
以下のように始まれば成功
$ brew install python
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:0c78b38f22fb9b42df6918db00e6f5a80d5b35164f910ffe4c89159326ae98cf
######################################################################################################################### 100.0%
==> Pouring portable-ruby-3.4.5.el_capitan.bottle.tar.gz
==> homebrew/core is old and unneeded, untapping to save space...
Untapping homebrew/core...
Untapped 4 commands and 7793 formulae (7,920 files, 1.7GB).
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
abpoa: SIMD-based C library for fast partial order alignment using adaptive band
act_runner: Action runner for Gitea based on Gitea's fork of act
adaptivecpp: SYCL and C++ standard parallelism for CPUs and GPUs
インストールに成功すると以下のコマンドで確認できる
python3 --version
自分が実施したときは以下のバージョンだったので、python3コマンドで実行した。
$ python3 --version
Python 3.13.6
python3のコマンドは2と3で大きな違いがあったため、明示化されたらしい。
macOSでエイリアスを貼る場合以下のコマンドで設定できる。
alias python=python3