Once Homebrew is installed, run the command brew update to ensure that you have the latest package information and formulas.
The output will be like this:
Updated 2 taps (homebrew/core and homebrew/cask).
To install Python, run the command brew install python — this will install the latest version of Python available in Homebrew’s database.
brew install python
If you want to install a specific version of Python, run the command brew install python@version. Let’s say you want to install Python’s 3.10 version, run the brew install email@example.com command:
brew install firstname.lastname@example.org
The output of the above command will be like this:
==> Fetching email@example.com ==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/manifests/3.10.9 Already downloaded: /Users/.../Library/Caches/Homebrewfirstname.lastname@example.org_manifest.json ==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/blobs/sha256:b6bfa7 Already downloaded: /Users/..../Library/Caches/Homebrewemail@example.com_ventura.bottle.tar.gz ==> Pouring firstname.lastname@example.org_ventura.bottle.tar.gz ==> /opt/homebrew/Cellaremail@example.com/3.10.9/bin/python3.10 -m ensurepip ==> /opt/homebrew/Cellarfirstname.lastname@example.org/3.10.9/bin/python3.10 -m pip install -v --n ==> Caveats Python has been installed as /opt/homebrew/bin/python3
i.e Python has been installed at the /opt/homebrew/bin/python3 location.
Creates a symbolic link (shortcut) to the Python 3 executable in the
/usr/local/bin directory, using the name “python” with ln -s /usr/local/bin/python3 /usr/local/bin/python command:
ln -s /usr/local/bin/python3 /usr/local/bin/python
If you want to use Python 3 as your default Python version on your system, but some of your scripts or programs are written with the assumption that the “python” command will run Python 2, you can use the above command to make them work with both versions.
Python has been installed via Homebrew on your MAC now. After the installation is completed with the above steps, you can check the version of python by running the command python -V
The output will be like this: Python 3.10.9
To test the Python, open a new Terminal window and type python.
The output will show you the version of python along with the Python terminal to play with:
Python 3.10.9 (v3.10.9:1dd9be6584, Dec 6 2022, 14:37:36) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information.
You can start typing print(“Hello World”) for example to see if it is working and the terminal will give you the Hello World output from that command:
>>> print(“Hello World”)
Output: Hello World
If you install Python using Homebrew, the version of Python that comes with OS X will be replaced with Homebrew’s version of Python. This can cause problems if you rely on a different version of Python for other projects.