Last modified: May 26, 2025 By Alexander Williams

Install Python on macOS with Homebrew

Installing Python on macOS is easy with Homebrew. Homebrew is a package manager for macOS. It simplifies installing software.

This guide will walk you through the steps. You will have Python running quickly.

Prerequisites

Before starting, ensure you have Homebrew installed. If not, install it first.

Open Terminal and run this command:


/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow the on-screen instructions. Homebrew will be ready in minutes.

Step 1: Update Homebrew

Always update Homebrew before installing new packages. This ensures you get the latest versions.

Run this command in Terminal:


brew update

This fetches the latest package lists. Your system stays up-to-date.

Step 2: Install Python

Now, install Python using Homebrew. The latest stable version will be installed.

Run this command:


brew install python

Homebrew handles all dependencies. Python will be ready shortly.

Step 3: Verify Installation

After installation, verify Python is installed correctly. Check the version.

Run this command:


python3 --version

You should see output like this:


Python 3.9.7

This confirms Python is installed. The version may differ.

Step 4: Set Up Pip

Pip is Python's package manager. It comes with Python installed via Homebrew.

Check Pip's version:


pip3 --version

Output will show Pip's version and location. Example:


pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

You can now install Python packages easily. For example, learn how to install Python packages from GitHub.

Step 5: Manage Python Versions (Optional)

Need multiple Python versions? Use pyenv. It lets you switch between versions easily.

Learn more in our guide on installing multiple Python versions with pyenv.

Step 6: Create Virtual Environments

Virtual environments keep projects isolated. They prevent dependency conflicts.

Create one with this command:


python3 -m venv myenv

Activate it with:


source myenv/bin/activate

Your prompt will change. Now, install packages without affecting the system.

For more details, see our guide on Python virtual environments.

Common Issues and Fixes

Sometimes, things don't go smoothly. Here are common issues and fixes.

Issue 1: Python command not found.

This happens if the PATH is not set. Ensure Homebrew's binaries are in your PATH.

Add this to your shell config file (e.g., ~/.zshrc or ~/.bashrc):


export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Then, reload the shell:


source ~/.zshrc

Issue 2: Outdated Python version.

Homebrew may not always install the latest. Update it with:


brew upgrade python

Conclusion

Installing Python on macOS with Homebrew is straightforward. Follow these steps, and you'll be set.

Homebrew simplifies managing Python and its dependencies. You can also explore other methods like installing Python from source.

Now, start coding in Python on your Mac. Happy coding!