Older Macs are bundled with an outdated version of Python that's no longer compatible with the latest applications. To run Python scripts on macOS Monterey or later, you'll have to download the most recent version of Python for macOS.

Follow along with our step-by-step guide right ahead as we show you how to download and install Python on your Mac and get started with running your very first script.

Do Macs Come With Python Pre-Installed?

For many years, Macs came with Python 2.7 pre-installed. However, this is no longer the case. While you can still download and install Python on a Mac, much like any other software, Apple no longer includes it by default as Python 2.7 is no longer maintained.

Apple had given early notices of removing it from its operating system in the release notes of macOS Catalina in 2019 before finally pulling the plug in macOS Monterey 12.3.

That being said, if your macOS version is anywhere between 10.8 to 12.3, there's a good chance that you still have Python 2.7 pre-installed on your Mac. The best way to check is by simply trying to run Python from the Terminal app in macOS.

How to Check the Pre-Installed Version of Python on Your Mac

If you're running an older version of macOS, you can check which version of Python is available on your Mac by following these steps:

  1. Launch the Terminal app on your Mac. To do this, go to your Mac's Launchpad and type Terminal in the search field. Alternatively, you can use Spotlight search to find it.
  2. Enter the following command to check Python 2.7's version and hit Return:
            python --version
        
    If Python is pre-installed, you'll get a response with details about the version.
    macOS Terminal showing the installed Python version
  3. If your Mac has multiple versions of Python, you can enter a command specifying the Python version. To check Python 2.7's version, you can use the python --version command. And for Python 3, you can use the following command:
            python3 --version
        
    macOS Terminal showing installed Python 3 version

How to Install Python With the Official Installer

The easiest way to download the newest version of Python is through its official website. Here's what you need to do to get started:

  1. Download the installer package from Python's official site.
    download python from the official website
  2. Wait for the download to complete. Once it's finished, double-click the package to start the installation process. You can follow the on-screen instructions in the Python installer for this step.
    python installer package
  3. Once the installation is complete, the installer will automatically open Python's installation directory in a new Finder window.
    python installation directory open in finder

Confirming Your Python Installation

You need to confirm that you've correctly installed Python and IDLE, the integrated development environment that comes with Python—just one of many vital tools for Python developers.

  1. In Python's installation directory, double-click the file name IDLE to launch it. If the installation is successful, IDLE will open a Python shell.
    python 3 IDLE shell
  2. To ensure everything is running smoothly, enter a simple Python print command and run it in IDLE.
            print('Hello, world!')
        
  3. Hit the Return (or Enter) key, and you should get your message printed on the interface if everything's functioning correctly.
    python 3 IDLE shell printing hello world
     

Install a Source-Code Editor on Your Mac

Now that you've installed Python on your Mac, you need to install a free code editor to help you make coding faster and easier. Even though the IDLE that comes as a part of the Python package is a source-code editor too, and you can use it to get started, some better editors provide a much more efficient coding environment.

For example, Visual Studio Code is among the best free code editors with syntax highlighting out there. It's lightweight, powerful—and, most importantly, completely free. Follow these steps to install Visual Studio Code on your Mac:

  1. You can download Visual Studio Code for free from the official website.
    visual studio code download page
  2. Once complete, click the downloaded file and extract its archived contents.
  3. Move Visual Studio Code to the Applications folder. Doing this makes it available in the macOS launchpad for easy access.
  4. Now, launch Visual Studio Code and create a new file by clicking New File...
    visual studio code home page
  5. For Visual Studio Code to read your file as a Python script, you must create one with the .py extension.
    visual studio code creating a new file
  6. Now, select a location to save your new Python script and click Create File.
    visual studio code selecting location to safe file
  7. Visual Studio Code will now prompt you to install a Python extension. You can do that by clicking the Install button.
    visual studio code pop up to install python extension
    However, If you missed clicking on the pop-up that asks you to install the extension or if you accidentally closed it, you can still manually install the Python extension. You can do this by clicking on the Extensions icon (four boxes) on the left side of Visual Studio Code. Doing this shows you a list of the most popular Python extensions in the Visual Studio Marketplace. Then, search for Python and install the first extension that appears in the search results.
    alternative method of installing extensions in visual studio code
  8. Lastly, choose your preferred Python interpreter. Click View > Command Palette, then type Python: Select Interpreter into the field at the top of the window and press Return. Use the arrow keys to highlight the interpreter next to Recommended in the search results, then press Return to select it.
    Setting the default Python interpreter in Visual Studio Code

Running Your First Python Script on a Mac

Getting this far into the process means you've successfully installed Python on your Mac and managed to set up a code editor. Now, it's time to run your first Python script on macOS. To do that, follow these instructions:

  1. Go back to the Python file you just created and enter any basic Python command like:
            print('Hello, world!')
        
  2. You can compile and run your code by clicking the Play button in the top-right corner of the Visual Studio Code window.
    visual studio code run code button
  3. If your code is written correctly, you'll get the output displayed in the integrated Terminal, which means you've successfully run your first Python script.
    visual studio code printed hello world

How to Uninstall Python From Your Mac

If you ever change your mind about using Python on your Mac and plan to switch to a different programming language, you can follow the steps below to remove Python from macOS.

Uninstalling Python From the Applications Folder

Go to Finder and click the Applications folder. Then, move all your installed Python folders into the Trash. To remove a single version, ensure you only move that specific version's files to the Trash.

delete python by moving folder to bin

A dialog box may pop up asking your permission to perform the deletion. Enter your Mac's password to grant Terminal permission to remove these files.

Uninstalling Python Framework From the /Library Directory

If you want to completely uninstall Python from your system, you also need to remove the Python framework from the /Library directory. The Python framework contains the Python interpreter, the standard library, and the site-packages folder.

Removing the Python framework will remove all of these files from your system. So, if you don't remove these files, Python will still be installed on your Mac but won't be usable.

  1. Hit the Command + Space to bring up Spotlight search on your Mac. Search for Terminal and launch it.
  2. Enter the following command in Terminal and hit the Return (or Enter) key.
            sudo rm -rf /Library/Frameworks/Python.framework
        
    terminal with command to delete python on mac
  3. Enter your Mac's password to grant permission to delete the files.
    terminal asking for password

This will delete the framework of all the versions of Python installed on your Mac. However, if you only want to delete the framework of a specific version (such as version 3.8), you can use the following command:

        sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.8
    

This will delete the framework of the specified version of Python from your Mac.

Getting Started With Python on macOS Is Easy

As a general-purpose programming language, Python prioritizes code readability. This makes Python easy to learn and read, letting you create versatile applications ranging from web development to data analysis and beyond.

Even though there are many ways to install Python on macOS, the safest way is to use the official installer. However, you can also use a package manager for macOS like Homebrew—an application that makes it easy to install and manage software, dependencies, and other scripts on your computer.

The best part is that you can not only use Homebrew to install any version of Python but also many other apps.