Install Python on macOS

Python tutorial · PySpark.in

Method 1 – Install Python using Official Installer

Step 1: Check if Python is already installed

Open Terminal:

In Terminal  run:

If you see something like:

Python 3 is already installed.

If you see “command not found” or a very old version, follow the steps below.


Step 2: Download Python from the official website

  1. Open Safari or Chrome
  2. Go to: python.org
  3. Click on Downloads → Python 3.x.x for macOS
  4. This will download a file like:
    python-3.xx.x-macosx.pkg

 Step 3: Run the installer

 Step 4: Verify Python installation

Open Terminal again and run:

If you see a version, you’re ready to install packages.

 Method 2 – Install Python using Homebrew (For Developers)

If you use Homebrew (or want to), this method is clean and dev-friendly.

Step 2: Install Homebrew (if not installed)

In Terminal, run:

to confirm Homebrew is installed.

Step 3: Install Python with Homebrew

Step 4: Verify Python

Step 5: Make sure the correct Python is used

Sometimes macOS has an old system Python (/usr/bin/python).
To always use Python 3, use python3 and pip3 in commands.

Example:

Don’t try to remove the system Python. macOS needs it.

 Step 6: Run your first Python program on Mac

Option 1: Run code directly in Terminal

In Terminal, type:

>>>

Now type:

Option 2: Run a .py file

  1. Create a file using TextEdit or VS Code or any editor.
  2. Save it as hello_mac.py (plain text, not rich text).

Put this inside:

Output:

 Step 7: Install useful Python packages

Use pip3 to install libraries:

 Note:

Step

What to do

Command / Action

1

Open Terminal

Command + Space → “Terminal”

2

Check Python

python3 --version

3

Install via official installer

Download from python.org & run .pkg

4

Verify pip

pip3 --version

5

Run script

python3 hello_mac.py

6

Install packages

pip3 install numpy pandas

More Python tutorials

All tutorials · Try the free PySpark compiler · Practice challenges