0
0
PythonHow-ToBeginner · 3 min read

How to Install Python on Mac: Step-by-Step Guide

To install Python on a Mac, you can use the Homebrew package manager by running brew install python in the Terminal. Alternatively, download the official installer from python.org and follow the setup steps.
📐

Syntax

There are two main ways to install Python on a Mac:

  • Using Homebrew: A package manager that simplifies software installation.
  • Using the official Python installer: Download the installer from the Python website.

Homebrew command syntax:

brew install python

This command downloads and installs the latest Python version.

bash
brew install python
💻

Example

This example shows how to install Python using Homebrew and verify the installation.

bash
brew install python
python3 --version
Output
Python 3.11.4
⚠️

Common Pitfalls

Common mistakes when installing Python on Mac include:

  • Trying to use python instead of python3 to run Python 3, since macOS may have Python 2 as python.
  • Not installing Homebrew before running brew install python.
  • Ignoring the need to update your PATH environment variable if the installer does not set it automatically.
bash
Wrong:
python --version

Right:
python3 --version
📊

Quick Reference

Summary tips for installing Python on Mac:

  • Install Homebrew first: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Use brew install python to install the latest Python.
  • Run python3 --version to check the installed version.
  • Use python3 to run Python scripts.
  • Alternatively, download the official installer from python.org.

Key Takeaways

Use Homebrew to install Python easily with the command 'brew install python'.
Always run Python 3 with the command 'python3' on Mac to avoid confusion with Python 2.
Verify your installation by checking the Python version with 'python3 --version'.
If Homebrew is not installed, install it first using the official script.
You can also install Python by downloading the official installer from python.org.