So, here’s a complete guide on installing Python on your Mac and getting started with running your first script.

Do Macs Still 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.

That being said, if your Mac’s version is anywhere between 10.8 to 12.3, there is 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 below:

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. 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 that will provide details about the version. 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

How to Install Python With the Official Installer

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

Download the installer package from Python’s official website. 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. Once the installation is complete, the installer will automatically open Python’s installation directory in a new Finder window.

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.

In Python’s installation directory, you’ll find a file named IDLE. Double-click on it to launch it, and if the installation is successful, IDLE will open a Python shell. To ensure everything is running smoothly, enter a simple Python print command and run it in IDLE. print(‘Hello, world!’) Hit the Return (or Enter) key, and you should get your message printed on the interface if everything’s functioning correctly.

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 that can 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.

So, if you want a lightweight and powerful code editor, you’ll need something like Visual Studio Code. And here’s how you can install it:

You can download Visual Studio Code for free from the official website. Once complete, click the downloaded file and extract its archived contents. Move VSCode to the Application folder. Doing this makes it available in the macOS launchpad for easy access. Now, launch VSCode and create a new file by clicking New File… For Visual Studio Code to read your file as a Python script, you must create one with the . py extension. Now, select a location to save your new Python script and click Create File. VSCode will now prompt you to install a Python extension. You can do that by clicking the Install button. 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 on the search results. After installing the Python extension, pick a Python interpreter by clicking the Select Python Interpreter button and selecting the recommended one from the list.

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:

Go back to the Python file you just created and enter any basic Python command like: print(‘Hello, world!’) You can compile and run your code by clicking the Play button at the top right corner of Visual Studio Code. 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.

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 Application folder. Move all your installed Python folders into the Trash. To remove a single version, ensure that you only move that specific version’s files to the Trash. 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.

Hit the Command + Space bar keys to bring up Spotlight Search. Here, search for Terminal and launch it. Enter the following command in Terminal and hit the Return (or Enter) key. sudo rm -rf /Library/Frameworks/Python. framework Enter your Mac’s password to grant permission to delete the files.

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:

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

Getting Started With Python on Your Mac Is Easy

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.