Introduction
Python is one of the most popular programming languages, used for web development, data analysis, automation, and much more. Installing Python on macOS is straightforward, but it's important to choose the right method to avoid path and version issues.
In this guide, we'll cover three main ways to install Python 3 on a Mac:
- Via the official installer from python.org (the simplest option).
- Via Homebrew—a package manager for macOS (convenient for developers).
- Via pyenv—a Python version manager (for those who need to switch versions frequently).
We'll also show how to verify that Python is installed correctly and how to configure the PATH environment variable if commands aren't working.
Before You Begin: Check if Python is Already Installed
macOS traditionally ships with Python 2.7 (in macOS up to 12 Monterey) or Python 3 (in newer versions starting with macOS 12.3). However, the system Python is often outdated and not intended for development.
Open Terminal (via Spotlight or Finder → Applications → Utilities) and run:
python3 --version
If you see something like Python 3.11.5, Python 3 is already installed. If the command is not found, or the version is too old (e.g., 3.8), you'll need to install a newer version.
💡 Tip: Always use the
python3command instead ofpythonto explicitly refer to Python 3. The systempython(if present) is Python 2.7.
Method 1: Installation via the Official Installer
This method is ideal for beginners. The installer from python.org automatically configures PATH and adds pip (Python's package manager).
Step 1: Download the Installer
- Go to the official website: python.org/downloads/macos/
- Select the latest stable version (e.g., Python 3.12.x). Download the 64-bit installer (a
.pkgfile).
Step 2: Run the Installer
- Open the downloaded
.pkgfile (e.g.,python-3.12.1-macos11.pkg). - Follow the installer wizard instructions. Keep all settings at their defaults.
- The installer will automatically:
- Install Python to
/Library/Frameworks/Python.framework/Versions/3.x - Add symbolic links to
/usr/local/bin/(the standard location for user programs on macOS). - Install pip (the package manager).
- Install Python to
Step 3: Verify the Installation
After installation completes, open a new Terminal window (important for environment variables to update) and run:
python3 --version
pip3 --version
You should see the installed versions. If commands don't work, you may need to restart Terminal or even your Mac.
⚠️ Important: The python.org installer does not overwrite the system Python 2.7. It installs Python 3 in a separate directory, which is safe.
Method 2: Installation via Homebrew
Homebrew is a package manager for macOS that simplifies installing and updating software from the command line. If you already use Homebrew for other tools (like Git, Node.js, etc.), this will be the most convenient method.
Step 1: Install Homebrew (if not already installed)
If Homebrew isn't installed, run in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions. After installation, add Homebrew to your PATH as the installer suggests (usually the command echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile for Apple Silicon or eval "$(/usr/local/bin/brew shellenv)" for Intel).
Verify the installation:
brew --version
Step 2: Install Python
Now install Python:
brew update
brew install python
Homebrew will install the latest Python 3 version and pip. All files will be placed in /opt/homebrew/Cellar/python/ (for Apple Silicon) or /usr/local/Cellar/python/ (for Intel), and symbolic links will be created in /opt/homebrew/bin/ or /usr/local/bin/.
Step 3: Verify the Installation
python3 --version
pip3 --version
Homebrew also provides the brew upgrade python command to update Python in the future.
💡 Tip: Homebrew manages dependencies, so if you're installing Python for development, this method is preferable—it's easier to update and integrates well with other tools.
Method 3: Installation via pyenv (for Advanced Users)
pyenv is a Python version manager that allows you to install and easily switch between multiple Python versions (e.g., 3.9 for one project and 3.12 for another). This method is suitable if you work with different projects requiring specific Python versions.
Step 1: Install pyenv via Homebrew
brew install pyenv
Step 2: Configure Your Shell
pyenv requires shell initialization (bash, zsh, fish). For zsh (default in macOS since 10.15), add to the ~/.zshrc file:
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
For bash, add to ~/.bash_profile:
echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
Restart Terminal or run source ~/.zshrc (or source ~/.bash_profile).
Step 3: Install the Desired Python Version
# List available versions
pyenv install --list
# Install a specific version (e.g., 3.12.1)
pyenv install 3.12.1
# Install the latest stable version
pyenv install 3.12
Step 4: Set a Global Version (Optional)
To use the installed version by default:
pyenv global 3.12.1
Now the python and python3 commands will point to this version.
⚠️ Important: pyenv manages Python versions in
~/.pyenv/versions/. It does not conflict with the system Python or Homebrew installations.
Configuring the PATH Variable (if Python is Not Recognized)
If after installation the python3 or pip3 command doesn't work, the path to Python might not be added to the PATH environment variable.
Where is Python Located?
- Official installer:
/Library/Frameworks/Python.framework/Versions/3.x/bin/ - Homebrew:
/opt/homebrew/bin/(Apple Silicon) or/usr/local/bin/(Intel) - pyenv:
~/.pyenv/shims/(added automatically during setup)
How to Add a Path to PATH?
- Determine which shell you're using. In Terminal, run:
echo $SHELL
If the output is /bin/zsh, it's zsh; if /bin/bash, it's bash.
- Open your shell's configuration file:
- For zsh:
nano ~/.zshrc(or any other editor) - For bash:
nano ~/.bash_profile
- For zsh:
- Add a line (substitute the correct path):
# For the official installer
export PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:$PATH"
# For Homebrew (Apple Silicon)
export PATH="/opt/homebrew/bin:$PATH"
# For Homebrew (Intel)
export PATH="/usr/local/bin:$PATH"
- Save the file (in nano:
Ctrl+X, thenY, thenEnter) and reload the shell:
source ~/.zshrc # or source ~/.bash_profile
- Verify:
which python3
echo $PATH
Verifying Installation and Your First Script
After installation, make sure everything works:
# Check Python version
python3 --version
# Check pip (package manager)
pip3 --version
# Create a test script
echo 'print("Hello, Python!")' > hello.py
# Run it
python3 hello.py
If you see Hello, Python!—Python is installed and working.
Common Issues and Solutions
Issue 1: command not found: python3
Cause: The path to Python is not added to PATH.
Solution: Follow the instructions in the Configuring the PATH Variable section.
Issue 2: Version conflict after installing via both Homebrew and the official installer
Cause: Both methods add their own paths to PATH, and the order may cause the wrong version to be used.
Solution:
- Check the path order:
echo $PATH. - Ensure the path to your desired Python version comes first.
- If needed, edit
~/.zshrcor~/.bash_profileto set the correct priority.
Issue 3: pip3 fails to install packages globally (permission error)
Cause: Attempting to write to system directories without administrator privileges.
Solution:
- Use the
--userflag to install to your home directory:
pip3 install --user package_name
- Or set up virtual environments (see What's Next?).
Issue 4: After pyenv installation, the python command still points to an old version
Cause: pyenv is not initialized in the current shell.
Solution:
- Ensure you added pyenv initialization to your shell config file (see Step 2).
- Restart Terminal or run
exec $SHELL.
What's Next?
Now that Python is installed, you can:
- Set up virtual environments—isolate dependencies for each project. Use the built-in
venvmodule:
# Create a virtual environment
python3 -m venv myenv
# Activate (for zsh/bash)
source myenv/bin/activate
# Install packages inside the environment
pip install requests
- Install an IDE or code editor:
- Visual Studio Code with the Python extension.
- PyCharm (Community Edition is free).
- Sublime Text or Atom.
- Upgrade pip:
pip3 install --upgrade pip
- Install popular packages to get started:
pip3 install numpy pandas matplotlib jupyter
- Write and run your first project—for example, a web app with Flask or Django.
Conclusion
Installing Python on macOS is a simple process that will take no more than 10 minutes. You can choose the official installer for maximum simplicity, Homebrew for convenient management, or pyenv for working with multiple versions.
After installation, remember to check the python3 and pip3 versions and configure PATH if commands aren't recognized. If you encounter issues, refer back to the Common Issues section.
Happy coding! 🐍