How to Install Python on Mac

Python is an adaptable programming language utilized for various applications such as web development, data analysis, automation, and beyond. macOS includes Python 2 by default; however, Python 2 has reached its end of life and is no longer maintained. It is recommended to install Python 3.

This manual offers a detailed procedure for installing Python 3 on macOS.

Looking for other platforms?

  • Install Python on Windows
  • Install Python on Ubuntu
  • Installing Python on Mac

    Method 1: Using the Official Installer (Recommended)

    Step 1: Download the Installer

  1. Open Safari or any web browser.
  2. Go to the official Python website: https://www.python.org/downloads/macos/**
  3. The website detects macOS and shows the latest stable version.
  4. Click the download button (for example, "Download Python 3.x.x").
  5. Step 2: Run the Installer

  6. Open your Downloads folder and double-click the .pkg file.
  7. Follow the installation wizard:
  • Click "Continue"
  • Agree to the license
  • Choose the installation location (default is recommended)
  • Click "Install"
  1. Enter your Mac password when prompted.
  2. Wait for the installation to complete.
  3. Step 3: Verify Installation

  4. Open Terminal (Command + Space, type "Terminal", press Enter).
  5. Run the command:
  6. Example
    
    python3 --version
    

You should see output like:

Example

Python 3.12.2
  1. Check pip installation:
  2. Example
    
    pip3 --version
    

    Method 2: Using Homebrew

Homebrew serves as a widely-used package manager for macOS, simplifying the processes of software installation and management.

Step 1: Install Homebrew (if not already installed)

Open Terminal and run:

Example

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

Step 2: Install Python with Homebrew

Example

brew install python

This installs the latest Python 3 version.

Step 3: Verify Installation

Example

python3 --version
pip3 --version

Step 4: Test Python in Terminal

  1. Open Terminal.
  2. Type:
  3. Example
    
    python3
    

You will observe the Python interactive prompt (>>>).

  1. Execute a brief test:
  2. Example
    
    print("Hello, World!")
    

Output:

Output

Hello, World!
  1. Exit the shell with:
  2. Example
    
    exit()
    

    Setting Python 3 as Default (Optional)

By default, the python command still points to Python 2 on macOS. To use python instead of python3:

  1. Open Terminal.
  2. Edit your shell configuration file:

For bash (older Macs):

Example

echo "alias python=python3" >> ~/.bash_profile
echo "alias pip=pip3" >> ~/.bash_profile
source ~/.bash_profile

For zsh (macOS Catalina and newer):

Example

echo "alias python=python3" >> ~/.zshrc
echo "alias pip=pip3" >> ~/.zshrc
source ~/.zshrc

Now you can use python and pip instead of python3 and pip3.

Uninstalling Python (If Needed)

If you have set up Python via the official installer:

  1. Launch Terminal.
  2. Execute:
  3. Example
    
    sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.x
    sudo rm -rf "/Applications/Python 3.x"
    

Replace 3.x with your Python version.

If you installed using Homebrew:

Example

brew uninstall python

Conclusion

Python has been successfully installed on your macOS. You can now create scripts, install packages, and begin developing projects.

How to Install Python on Mac 1.FAQs

1. Does Mac come with Python?

Indeed, macOS comes with Python 2 pre-installed; however, Python 2 is no longer supported. It is advisable to install Python 3 for any new projects.

2. Which Python version should I install on Mac?

Obtain the most recent stable version of Python 3 from python.org or by utilizing Homebrew.

3. How do I check if Python is installed on Mac?

Open Terminal and run:

Example

python3 --version

4. What is the difference between python and python3 commands?

  • python typically points to Python 2 (deprecated).
  • python3 points to Python 3 (recommended).

An alias can be established to utilize python with Python 3.

5. Should I use Homebrew or the official installer?

Both choices are viable:

  • Official installer: More user-friendly for novices, provides a standard setup.
  • Homebrew: More suitable for developers handling various tools, simplifies the updating process.
  • 6. How do I update Python on Mac?

Utilizing the official installer: Acquire and set up the latest version from python.org.

Using Homebrew:

Example

brew upgrade python

Input Required

This code uses input(). Please provide values below: