Advertisement

How to Set Up Python on Mac: Complete Guide

Macs actually come with Python pre-installed, but it's usually an old version. Setting up a current version is pretty straightforward. I've set up Python on dozens of Macs, and I'm going to walk you through the easiest way.

By the end of this guide, you'll have Python installed, verified, and ready to use.

Step 1: Check What You Have

Macs come with Python 2.7 (old and deprecated) and sometimes Python 3. Let's check:

Open Terminal (Applications → Utilities → Terminal) and type:

python3 --version

If you see Python 3.x (like 3.9, 3.10, 3.11, or 3.12), you might already have a recent version. But it's better to install the latest version properly.

Don't use: python --version - that's Python 2.7, which is outdated.

Step 2: Install Homebrew (Recommended)

Homebrew is a package manager for Mac. It makes installing software easy. I recommend using it:

  1. Open Terminal
  2. Paste this command:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Follow the prompts (it'll ask for your password)
  4. Wait for it to finish (takes a few minutes)

Homebrew is useful for installing lots of software on Mac. Once you have it, you'll use it for other things too.

Step 3: Install Python with Homebrew

Once Homebrew is installed:

brew install python

This installs the latest Python. It takes a few minutes.

Alternative: If you don't want to use Homebrew, you can download Python from python.org (see Step 4).

Step 4: Alternative - Install from python.org

If you don't want to use Homebrew:

  1. Go to python.org
  2. Click "Download Python" (it'll detect you're on Mac)
  3. Download the .pkg file
  4. Run the installer
  5. During installation, check "Add Python to PATH" if the option appears

The installer is straightforward - just click through it.

Step 5: Verify Installation

Open Terminal and check:

python3 --version

You should see something like "Python 3.12.0" (version might be different). If you see this, Python is installed!

Note: On Mac, use python3 not python. The python command points to the old Python 2.7.

Step 6: Test Python

Let's make sure Python actually works:

python3

You should see the Python prompt (>>>). Type:

print("Hello, Python!")

Press Enter. You should see "Hello, Python!" printed. Type exit() to leave Python.

Step 7: Install pip

pip is Python's package manager. It should be installed with Python, but let's check:

pip3 --version

If you see a version number, pip is installed. If not, install it:

python3 -m ensurepip --upgrade

Note: Use pip3 not pip on Mac, just like with Python.

Step 8: Create an Alias (Optional)

Typing python3 every time is annoying. Create an alias:

  1. Open Terminal
  2. Edit your shell config file:
    • If using bash: nano ~/.bash_profile
    • If using zsh (default on newer Macs): nano ~/.zshrc
  3. Add these lines:
    alias python=python3
    alias pip=pip3
  4. Press Ctrl+X, then Y, then Enter to save
  5. Restart Terminal or run: source ~/.zshrc (or source ~/.bash_profile)

Now you can use python instead of python3.

Advertisement

Common Issues and Fixes

  • "python3: command not found": Python isn't installed or isn't in PATH. Install it using Homebrew or from python.org.
  • Wrong Python version: Make sure you're using python3, not python. Check version with python3 --version.
  • Permission errors: If you get permission errors, you might need to use sudo, but try without it first. Using sudo with pip can cause problems.
  • Multiple Python versions: Macs can have multiple Python versions. Use which python3 to see which one you're using.

Recommended: Install a Code Editor

While you can write Python in any text editor, a proper code editor makes life easier:

  • VS Code: Free, popular, excellent Python support
  • PyCharm: Made specifically for Python. Free community edition
  • Sublime Text: Lightweight and fast

I recommend VS Code - it's free, works great, and has excellent Python extensions.

Next Steps

Now that Python is installed:

  • Start learning Python basics
  • Write your first Python program
  • Install useful packages with pip
  • Set up a development environment

Check out our Python for Beginners course to get started coding!

Pro Tip: Keep Python updated. New versions come out regularly. Update Homebrew (brew update && brew upgrade) or download new versions from python.org. Also, use virtual environments for projects - they keep dependencies organized.

Common Questions

Do I need to uninstall the old Python?

No. Mac's system Python (2.7) is used by the system. Don't delete it. Just use python3 for your work. Having multiple versions is fine.

Should I install Python from python.org or Homebrew?

Either works. Homebrew is easier to update and manage, but python.org installer is fine too. I prefer Homebrew because it's easier to manage multiple packages.

What's the difference between python and python3?

On Mac, python points to Python 2.7 (old, deprecated). python3 points to Python 3.x (current). Always use python3 for new projects.

You're Ready to Code

Python is installed and working. Now the fun part - start writing code! Open a text editor, write a simple program, and run it with python3 yourfile.py. The more you practice, the better you'll get. Check out our Python beginner's course to get started.

Advertisement