Get Started with Programming and Install Python on macOS

Published:22 August 2023 - 4 min. read

Michael Nguyen Tu Image

Michael Nguyen Tu

Read more tutorials by Michael Nguyen Tu!

Azure Cloud Labs: these FREE, on‑demand Azure Cloud Labs will get you into a real‑world environment and account, walking you through step‑by‑step how to best protect, secure, and recover Azure data.

In this digital age, having access to a powerful programming language like Python is essential for unleashing your creativity in development. Python allows users to interpret statements in several operating systems (OSes), but how do you install Python on macOS devices?

In this tutorial, you will learn two ways to install Python on macOS, so you can later delve into building websites, machine learning, and software testing.

Keep reading to take your project to new heights with Python!

This tutorial comprises hands-on demonstrations. Ensure you have the following in place to follow along with this tutorial:

  • A device running macOS 10.8 or later – This tutorial uses a Mac computer running macOS 11.7 (Big Sur).
  • Homebrew installed on your macOS device.

Enforcing Homebrew to Install Python on macOS

The quickest way to install Python on your macOS device is via Homebrew, a popular package manager. Homebrew simplifies the installation and management of various software packages, including Python.

To install Python on your macOS device via Homebrew, follow these steps:

1. Open your terminal, and run the below brew command to update Homebrew. This command fetches the latest information about available software packages and their versions.

brew update
install python on macos - Updating Homebrew
Updating Homebrew

2. Next, execute the following command to install python on your device.

brew install python
Installing Python on your device
Installing Python on your device

3. Lastly, run the following python3 command to verify that Python is installed on your device.

python3 --version

You will see the currently installed Python version number (3.11.4) on your macOS device.

Checking the installed Python version
Checking the installed Python version

Installing Python on macOS via the Official Installer

If you would rather not install Python via Homebrew, that is fine; not all people like to use Homebrew. But worry not. Another way you can install Python on your macOS device is via the official installer from the Python website.

Installing via the official installer is slightly more complicated and requires you to go through multiple steps. But on a good note, this method allows you always to get the latest version of Python, and take advantage of the latest features, improvements, and security updates.

1. Open your favorite web browser, and visit the official Python download page for macOS.

2. Next, locate the latest version of Python 3, which, at this time of writing, is Python 3.12.0rc1, and click the download link under it to download the installer.

Downloading the latest Python installer from the official Python download page
Downloading the latest Python installer from the official Python download page

3. Once the download completes, double-click on the installer to initialize the installation process.

4. Now, click Continue in the installer window to continue with the installation.

Continuing with the Python installation
Continuing with the Python installation

5. Read the displayed information and click Continue to continue.

6. Read through the software license agreement, and click Continue.

Reading the software license agreement
Reading the software license agreement

7. When prompted, click Agree to accept the software license agreement and continue with the installation.

Accepting the software license agreement
Accepting the software license agreement

8. Next, click Continue to perform installing Python on your macOS device.

If you are wondering, you cannot select the installation destination, as it will automatically be installed by default.

Installing Python via the official installer
Installing Python via the official installer

9. Provide your user password when prompted, and click Install Software to authenticate the installation.

Providing credentials to authenticate the Python installation
Providing credentials to authenticate the Python installation

Wait for the installation to complete.

Waiting for the installation to complete
Waiting for the installation to complete

10. Once the installation completes, click Close to finalize and close the installer.

At this point, you have successfully installed the latest version of Python on your macOS device.

Once the installation completes, click Close to close the installer
Once the installation completes, click Close to close the installer

11. Open the Application folder, and you will see the newly-installed Python application.

Viewing the newly-installed Python application
Viewing the newly-installed Python application

12. Ultimately, run the below command in your terminal to check the version of Python installed on your macOS device.

python3 --version
Checking the installed Python version
Checking the installed Python version

Installing the PIP Package Manager

Although Python comes with many useful packages for development, you may want to install additional ones, like the PIP package manager. PIP allows you to seamlessly install and manage various additional packages to enhance your development environment.

1. Execute the following python3 command to install your system’s PIP package manager (ensurepip).

python3 -m ensurepip
Installing the PIP package manager
Installing the PIP package manager

2. Next, run the below command to --upgrade PIP (ensurepip) to the latest version

python3 -m ensurepip --upgrade
Upgrading PIP to the latest version
Upgrading PIP to the latest version

3. Now, run the pip3 command below and check the installed PIP version on your system.

pip3 --version

The latest version at this time of writing is pip 23.2.1, as shown below.

Checking the installed PIP version
Checking the installed PIP version

Testing the Python Installation

With Python wholly installed on your system, how do you check your Python installation works correctly? The best way to test your Python installation is to run small programs.

In this example, you will launch Python in interactive mode, which allows you to run Python commands and instantly observe their outcomes directly. This capability provides an efficient means to validate your installation.

To test your Python installation, follow the steps below:

1. Execute the following python3 command, without any parameters or options, to initiate the Python interpreter in interactive mode.

python3

You will see your prompt changes to >>>, as shown below, which indicates the interpreter is ready to accept commands.

Initiating the Python interpreter in interactive mode
Initiating the Python interpreter in interactive mode

2. Next, run the below command to print a Hello world message directly in the interactive mode.

print('Hello world')

If everything works correctly, you will see the following output.

Printing a message
Printing a message

3. Finally, run the exit() command below to exit the interactive mode and return to your default command prompt.

Exiting the interactive mode
Exiting the interactive mode

Conclusion

This tutorial has guided you through installing Python on your macOS device. You have also tested your installation works by launching Python in interactive mode and printing a simple message.

What you have seen in this tutorial is just the tip of the iceberg. Python is cable of doing much more as it supports program modularity and code reuse. Python has become enticing for Rapid Application Development as a high-level programming language with dynamic semantics.

Now, why not explore more of Python’s prowess? Perhaps start running Python scripts with Python and feel its automation power first-hand?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!