Home >System Tutorial >MAC >Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Joseph Gordon-Levitt
Joseph Gordon-LevittOriginal
2025-03-05 10:48:18550browse

Python has become one of the most popular programming languages ​​in the world with its incredible versatility. Whether you plan to build a website or an application yourself in Python, or want to run software that requires Python, you may need to install Python on your Mac.

This guide will discuss three of the most popular ways to get Python on your Mac and briefly introduce some alternatives.

Does the Mac system come with Python?

Unfortunately, since macOS Catalina, Mac computers no longer have Python pre-installed, although it is included in older versions of the OS, including Mojave and earlier. If you want to use Python on your Mac today, you need to set it up and manage it yourself.

Even if you are running an OSX version containing Python, it may be an old version now—especially if you are not deliberately manually updating it. Given this, it's better to make sure you're running the latest version before you start using it.

How to check if Python is installed on your Mac

There is an easy way to check if Python is installed on your Mac:

  1. Start Terminal from the Applications > Utility folder.
  2. Enter the command python3 and press Enter.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

If you have Python installed on your Mac, you will see the version number. If not, you will receive an error message.

How to install Python on Mac

You can get Python on your Mac in a number of different ways, some of which are simpler than others, and all work on Apple silicon chips (M1, M2, M3, and M4 chips) and Intel machines.

The following are three common methods that do not require much effort:

  1. Install Python on Mac through the installer
  2. Install Python on macOS using Rye
  3. Install Python on MacBook using Homebrew

Choose the right installation method depends on your needs. If you only need Python to run programs and utilities that depend on it, an easy way to use the official Python installer should be great for you. However, if you are developing in Python in multiple environments, the Rye option is ideal.

Before proceeding, if you already have an older version installed, you may need to uninstall Python from your Mac. If you do not set up a virtual environment for each required version, installing a different version can lead to conflicts, which is actually only necessary for more complex Python projects.

1. Install Python on Mac through the installer

Installing Python on your Mac using the official installer is one of the fastest ways to get it up and running, and if you just want to run Python programs and tools, this may be all you need. Just follow the steps below:

  1. Download the latest version of Python from the official website
  2. Run the installer
  3. Verify installation

1.1 Download the latest version of Python from the official website

First of all, you need the official Python installer:

  1. Download Python 3 from the macOS section on python.org.
  2. Click on "Latest Python 3 Version" at the top of the page.
  3. Scroll down to the Files section and select macOS 64-bit Installer.
  4. When the system prompts you to continue, click "Allow".

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

1.2 Run the installer

After downloading of the Python installer is completed, you can run it:

  1. Open your Downloads folder in Finder and double-click the Python package to run it.
  2. When the "Install Python" window appears, click "Continue" and follow the steps on the screen.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

1.3 Verify installation

After the Python installer is finished, a new Python folder will appear, containing the official IDE (integrated development environment) called IDLE, the Python launcher, and some text documents. This means that Python has been installed successfully, but you can verify the installation using the above steps.

2. Install Python on macOS using Rye

If you use Python for programming, you may need more advanced settings, especially if you plan to write more complex projects. A good option is to install Python using Rye, which allows you to install multiple "toolchains" simultaneously, which are essentially different versions of Python.

The following is how to install Python on your Mac using Rye:

  1. Installation Rye
  2. Set Rye's PATH
  3. Verify Rye Installation
  4. Verify Python installation

2.1 Install Rye

You can quickly download and install Rye using the curl command in the terminal. Please follow the steps below:

  1. Use the administrator account to open the terminal.
  2. Enter curl -sSf https://rye.astral.sh/get | bash and press Enter. Press the y key to continue when prompted.
  3. The system will ask you which package installer you want to use: uv or pip-tools. While UVs are updated and faster, pip offers better compatibility. It's also more friendly for beginners, as many tutorials mention pip. Use the arrow keys on the keyboard to select pip-tools and press Enter.
  4. Next, you will be asked which Python setting you want. Select Run Python installed and managed by Rye, and press Enter.
  5. Then, you need to select a version of Python you want to use as the default toolchain. Typically, it is recommended to use the latest version of Python, so unless you want another version, just press Enter.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

2.2 Setting Rye's PATH

Rye After completing the Python installation, you will be asked if you want to add Rye to the PATH via .profile. This is usually best on Linux, but on macOS, it is best to set PATH in .zprofile. So let's set the PATH manually as follows:

  1. When asked if you want to add Rye to PATH via .profile, type n to reject.
  2. Now we need to open the ~/.zprofile file for editing. In the terminal, type open -e ~/.zprofile and press Enter.
  3. By default, the file will be opened in TextEdit, a built-in text editor for Mac. However, if you have changed the text editor to a Notepad alternative to Mac or a similar editor, the .zprofile file will open in it.
  4. In the last line of your .zprofile configuration file, enter source "$HOME/.rye/env", and save and close the file. You need to close and reopen the terminal to start a new session for the changes to take effect.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

When Rye's PATH is set, the Python or Python3 command will now use the Python version installed by Rye, which is exactly the expected result. To confirm that the PATH is correct, type the echo $PATH command into the terminal and press Enter. Your directory should have *.rye/shims at the beginning.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

2.3 Verify Rye Installation

After completing the above steps, verify that Rye installation is simple:

  1. In the terminal, type rye --version, and press Enter.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

The version number should be displayed. If you see an error, check that you entered the correct command and that you followed the installation steps correctly.

2.4 Verify Python installation

Verify that Python installation is also easy, as shown below:

  1. In the terminal, type python --version and press Enter to display the Python version number.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

If you see "zsh: command not found error", check that you have set PATH correctly by repeating the above steps.

3. Install Python on MacBook using Homebrew

If you want to build a simpler project with Python, it's quite easy to install Python using Homebrew, as shown below:

  • Preinstalled Python
  • Check Homebrew is ready
  • Brew Installation
  • Verify using brew list
  • Brew pin
  • Update Python with Homebrew
  • Set $PATH of Homebrew Python
  • Verify Python installation

3.1 Preinstalled Python

If you are a software developer, you may have installed Xcode on your Mac, including a Python version. It is important that you don't delete it. Instead, we will use Homebrew to install the latest version. However, for security reasons, Anaconda and other third-party tools can be uninstalled from your MacBook.

One of the fastest ways to uninstall older versions of Python and other unwanted applications on your Mac is to use MacKeeper's Smart Uninstaller. It recognizes all software installed on your Mac and allows you to delete multiple programs and their associated files in just a few clicks.

The following is how to use it:

  1. Select Smart Uninstaller in the MacKeeper sidebar and click "Start Scan".
  2. After the scan is complete, select all the applications, widgets, plugins, and other items you want to uninstall, and click "Delete Selected Projects" to delete them.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

3.2 Check if Homebrew is ready

Before you can install Python with Homebrew, you need to make sure it is ready and updated:

  1. Open the terminal, type the brew update command, and press Enter.
  2. After any updates are finished, verify that Homebrew is ready to install the package by typing brew doctor and pressing Enter.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

If Homebrew is not installed, you will see the "zsh: command not found" error. To install it, copy and paste /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" into the terminal, press Enter and follow the on-screen steps.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

3.3 Brew installation

Homebrew is ready and updated, we can now install Python:

  1. Type brew install python into the terminal and press Enter.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

3.4 Verify using brew list

After the installation process is completed, we can verify that Python is installed correctly:

  1. Type brew list python into the terminal and press Enter to view the list of installed files.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

3.5 Brew pin

Homebrew will update Python as needed, but you may want to prevent this from happening – especially with some projects relying on a specific version of Python. You can use pin to prevent automatic updates:

  1. In the terminal, type brew pin python, and press Enter.
  2. You will not receive a response from the above command, but you can verify that it is valid by typing brew info python. You should see pinned at the end of your Python version number.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

If you want to update or reinstall Python with Homebrew in the future, you can delete the pin by typing the brew unpin python command.

3.6 Upgrade Python with Homebrew

To upgrade Python with Homebrew, just type brew upgrade python into the terminal and press Enter. Note that we are using upgrade instead of update here, because the update command is used for Homebrew itself.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Remember that some of your projects and programs may require a specific version of Python to work properly. It is recommended that you check these dependencies before performing an update to avoid breaking anything you need.

3.7 Set $PATH of Homebrew Python

After installing Python with Homebrew, you need to manually set $PATH, which is normal in most installation methods. Here's how to do this:

  1. In the terminal, enter open -e ~/.zprofile to open the configuration file in TextEdit.
  2. On the last line of the file, enter export PATH="$(brew --prefix python)/libexec/bin:$PATH", and save and close it. Your Homebrew version of Python will now take precedence over any other Python installation, but remember to close and restart the terminal for the changes to take effect.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Install Python on Mac: What Is the Best Way to Do This on MacOS?

3.8 Verify Python installation

To verify that Python is installed correctly using Homebrew, type which python into the terminal and press Enter. You should see the Python version number and the PATH you set above.

Install Python on Mac: What Is the Best Way to Do This on MacOS?

Other ways to install Python on Mac

Depending on how you want to use Python, other installation methods may be more appropriate. The methods we've covered in detail above are some of the most common methods that should suit most use cases, but if they don't meet your needs, you may want to consider installing Python with pyenv or Conda.

The best way to install Python on Mac

One of the big advantages of Python is that it is very flexible. No matter how you want to use it, you will find a setup method that perfectly matches your needs. For most Mac users, we recommend two options: the official Python installer for running Python applications, and for development using Rye.

If you need to remove Python programs and other unwanted software, check out MacKeeper's Smart Uninstaller. It can clear all unwanted applications and delete all associated files at once, while other uninstall methods usually leave these files behind.

The above is the detailed content of Install Python on Mac: What Is the Best Way to Do This on MacOS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn