How To Install And Set Up Python On Mac For Beginners

Why Python on Your Mac Feels More Complicated Than It Should

You’ve decided to start a new project, maybe a data analysis script, a web scraper, or you’re diving into machine learning. The tutorial says “first, make sure Python is installed.” You open your Mac’s Terminal, type `python3 –version`, and are met with a version number. Great, it’s there. You try to install a package with `pip` and get a “command not found” error. Or worse, you get permission errors. Suddenly, what seemed like a simple first step has you searching forums and Stack Overflow.

This confusion is the most common first hurdle for new Mac developers. macOS comes with a system Python, but it’s outdated, locked down by Apple for system use, and not meant for your projects. Trying to use it leads to a tangled mess of permission issues and version conflicts. The right approach is to install a separate, clean, user-controlled version of Python. This guide will walk you through the safest, most professional methods to get a fully functional Python environment on your Mac, ready for real work.

Understanding the macOS Python Landscape

Before installing anything, it’s crucial to know what you’re dealing with. Your Mac already has Python 2.7 and Python 3 installed by Apple. You can see them in `/usr/bin/`. These are system tools used by macOS itself for various scripts and utilities.

You should never modify or install packages into these system Pythons. Using `sudo pip install` here can break macOS system scripts and cause instability. Furthermore, the system Python 3 is often several versions behind the latest release. Your goal is to install a fresh, independent Python interpreter in a user-controlled location, completely separate from the system.

The Two Best Paths for a Clean Installation

For most users, there are two primary, recommended methods: using the official Python.org installer or using a version manager called `pyenv`. The best choice depends on your needs.

– The Official Installer from Python.org is the most straightforward. You download a `.pkg` file, run it, and get a working Python in `/Library/Frameworks/Python.framework`. It’s simple and perfect for beginners or those who need a single, stable version.

– Pyenv is a powerful tool for developers who work on multiple projects requiring different Python versions. It lets you install and switch between versions (like 3.9, 3.10, 3.11) seamlessly on a per-project basis. It’s a bit more setup but is considered a best practice in the Python community.

We will cover both methods in detail. We’ll also cover the critical next step: setting up `pip` and virtual environments, which are non-negotiable for managing project dependencies cleanly.

Method 1: The Straightforward Official Installer

This is the quickest way to get a fully functional, modern Python on your Mac. Follow these steps precisely.

Downloading the Right Package

First, open your web browser and go to the official Python downloads page at python.org. The site will usually detect you’re on macOS and present the correct download link. Do not download the first link you see labeled “macOS 64-bit universal2 installer” if you are on an Apple Silicon Mac (M1, M2, M3).

For the most compatible and trouble-free experience, scroll down to the “Stable Releases” section and look for the macOS installer. If you have an Intel Mac, choose the “macOS 64-bit Intel-only” installer. If you have an Apple Silicon Mac, the “universal2” installer works, but for absolute certainty, the Intel-only installer will also run perfectly via Rosetta 2. Download the `.pkg` file.

Running the Installation Wizard

Locate the downloaded file (usually in your `Downloads` folder) and double-click it. This launches the Python installer package. Click through the introduction and license agreement. On the “Installation Type” screen, this is critical: you must click “Customize” before proceeding.

In the customization window, ensure the box for “Install pip” is checked. This is the package manager and is essential. Also, check the box that says “Add Python to PATH”. This last option is what allows you to type `python3` in the Terminal and have it work. If this option is grayed out or not present, don’t worry; we will handle the PATH manually later. Click “Install” and authenticate with your Mac password.

Verifying the Installation

After the installer finishes, open the Terminal application (you can find it via Spotlight search with Command+Space, then type “Terminal”). In the new Terminal window, type the following command and press Enter:

`python3 –version`

You should see output like `Python 3.12.3` (the version number will match what you downloaded). This confirms the main interpreter is installed. Next, check that `pip` was installed by typing:

`pip3 –version`

You should see information about pip’s version and its installation location, which should be in `/Library/Frameworks/Python.framework` and not in `/usr/bin`. If the `pip3` command is not found, we will fix it in the troubleshooting section.

Method 2: The Flexible Power-User Approach with Pyenv

If you plan to do serious Python development, `pyenv` is the industry-standard tool for managing multiple versions. It installs Python versions into your user directory (`~/.pyenv`), leaving the system completely untouched.

Installing Pyenv Using Homebrew

The easiest way to install `pyenv` is via Homebrew, a package manager for macOS. If you don’t have Homebrew, install it first by pasting this command into Terminal:

how to setup python on mac

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

Follow the on-screen prompts. After Homebrew is installed, it will give you commands to add it to your PATH. Run those commands as instructed. Then, install pyenv:

`brew install pyenv`

Next, you need to add pyenv to your shell’s startup script so it loads every time you open Terminal. The commands differ slightly based on whether you use Zsh (the default on modern macOS) or Bash.

For Zsh (macOS Catalina and later):

`echo ‘export PYENV_ROOT=”$HOME/.pyenv”‘ >> ~/.zshrc`

`echo ‘command -v pyenv >/dev/null || export PATH=”$PYENV_ROOT/bin:$PATH”‘ >> ~/.zshrc`

`echo ‘eval “$(pyenv init -)”‘ >> ~/.zshrc`

Then, reload your shell configuration:

`source ~/.zshrc`

Installing and Using Python Versions with Pyenv

Now you can see all available Python versions:

`pyenv install –list`

To install the latest stable version of Python 3.12 (for example):

`pyenv install 3.12.3`

This will download and compile Python. Once done, set this version as your global default:

`pyenv global 3.12.3`

Close and reopen your Terminal. Now, when you type `python –version` (note, not `python3`), it will show the version you installed via pyenv. The `pip` command will also be available directly. The beauty of pyenv is you can install another version, like `3.11.9`, and set a specific project directory to use it with `pyenv local 3.11.9`.

The Essential Next Step: Mastering Virtual Environments

Regardless of which installation method you used, you must never install Python packages globally (i.e., directly with `pip install package_name`). This leads to dependency conflicts between projects. The solution is a virtual environment: an isolated folder that contains a copy of Python and its own `pip`-managed packages.

Creating and Activating Your First Virtual Environment

Navigate to your project directory in Terminal. Then, create a virtual environment. The command differs slightly based on your Python installation.

how to setup python on mac

If you used the official installer or pyenv’s Python 3.3+, the standard module is `venv`:

`python3 -m venv my_project_env`

This creates a folder called `my_project_env`. To start using the isolated environment, you must activate it:

`source my_project_env/bin/activate`

You’ll notice your Terminal prompt changes, usually prefixed with `(my_project_env)`. This means any `pip install` commands will now install packages only into this environment. Your global Python remains untouched.

Working Within and Leaving the Environment

With the environment active, you can install packages safely. For example:

`pip install requests pandas`

These packages are installed in `my_project_env/lib`. You can run your Python scripts as normal, and they will use the packages from this environment. When you’re done working, deactivate the environment to return to your global Python:

`deactivate`

The prompt will return to normal. Remember to activate the environment every time you open a new Terminal window to work on that project. A common practice is to list all project dependencies in a `requirements.txt` file using `pip freeze > requirements.txt`. Others can then recreate the environment with `pip install -r requirements.txt`.

Solving Common Post-Installation Hiccups

Even with careful steps, you might hit a snag. Here are solutions to the most frequent issues.

Command “pip3” Not Found After Official Install

If `pip3 –version` fails, the installer may not have added Python to your system PATH. Let’s check. In Terminal, type:

`echo $PATH`

Look for a path containing `Python.framework`. If you don’t see it, you need to add it manually. The exact path depends on your Python version. For Python 3.12 installed via the official installer, it’s typically:

`/Library/Frameworks/Python.framework/Versions/3.12/bin`

To add it temporarily for your current Terminal session:

`export PATH=”/Library/Frameworks/Python.framework/Versions/3.12/bin:$PATH”`

To add it permanently for Zsh, add the above line (without the word `export`) to your `~/.zshrc` file using a text editor, or run:

`echo ‘export PATH=”/Library/Frameworks/Python.framework/Versions/3.12/bin:$PATH”‘ >> ~/.zshrc`

how to setup python on mac

Then run `source ~/.zshrc`.

SSL Certificate Errors When Using Pip

Sometimes, especially on older macOS versions or corporate networks, `pip install` fails with an SSL: CERTIFICATE_VERIFY_FAILED error. This is because Python cannot find macOS’s certificate store. The fix is to run a script provided by the Python installer.

Open Terminal and run:

`/Applications/Python\ 3.12/Install\ Certificates.command`

Make sure the path matches your installed Python version number. This command installs a set of root certificates.

Pyenv Installation Fails Due to Missing Build Tools

When you run `pyenv install 3.12.3`, you might see an error about missing headers or a failed build. This is because pyenv compiles Python from source, which requires the Xcode Command Line Tools. Install them with:

`xcode-select –install`

Click “Install” in the pop-up dialog and agree to the license. After it completes, try the `pyenv install` command again.

Your Actionable Python Setup Checklist

To ensure you have a robust setup, follow this final checklist.

– Choose your installation method: Official PKG for simplicity, pyenv for version management.

– Verify installation with `python3 –version` or `python –version` (for pyenv).

– Verify pip is available with `pip3 –version` or `pip –version`.

– Immediately create a virtual environment for your first project using `python3 -m venv env_name`.

– Activate the environment with `source env_name/bin/activate` before installing any packages.

– Install your project dependencies using `pip install` while the environment is active.

– Create a `requirements.txt` file with `pip freeze > requirements.txt` to share your project’s setup.

You now have a professional-grade Python development environment on your Mac. It’s isolated, manageable, and free from system conflicts. This foundation will save you countless hours of debugging dependency issues down the road. The initial setup is the hardest part; from here, you can focus on writing code and building your projects. Open your editor, activate your virtual environment, and start creating.

Leave a Comment

close