TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Programming Languages / Python / Software Development

Getting Started With Python on MacOS

There are a couple of ways you can install Python on macOS, neither of which are all that challenging.
Oct 27th, 2024 9:00am by
Featued image for: Getting Started With Python on MacOS
Featured image via Unsplash.

When I work with Python, I’m always working on my go-to OS, Linux. Besides Linux being my default operating system, one of the reasons why I lean toward the open source OS for Python is that most distributions ship with the language pre-installed, which means I can dive right in without having to bother installing anything (outside of various libraries I might need).

But Linux isn’t my only OS. I also use macOS for certain tasks (especially video editing). If I want to work with Python on macOS, I can’t just open a terminal window and have at it because the language isn’t installed by default. Fortunately, there are a couple of ways you can install Python on macOS, neither of which are all that challenging.

Let me show you how it’s done.

First, the easy option.

What You’ll Need

The only thing you’ll need for this is a macOS device running an updated version of the OS. That’s it. Let’s get busy.

The Easy Method

It should come as no surprise that the Python team has created universal installers for macOS. Although you can download the file from your default web browser, I’m going to demonstrate how it’s done from the command line (seeing as how you’ll often use the terminal window for Python development).

Open the macOS Terminal app (or a different terminal if you’ve installed one). Next, make sure you’re downloading the latest version of Python by checking the official download page. Let’s say you’re going to install version 3.13.0rc2 (which is the latest version as of Sept.6, 2024). Change into your Downloads directory with:

cd ~/Downloads

Download the installer with:

wget https://www.python.org/ftp/python/3.13.0/python-3.13.0rc2-macos11.pkg

Next, to install Python from the command line, issue the following:

sudo installer -pkg ~/Downloads/python-3.13.0rc2-macos11.pkg -target /

Close the terminal window and re-open it (otherwise you’ll receive errors when attempting to run any Python command). Verify the installation with the command:

python3 –version

You should see the version information printed into the output.

At this point, you’re ready to start developing with Python.

The Not-So-Easy Method

If you’d rather take the not-so-easy route for installing Python, there’s always Brew, which is a command line package manager that makes it easy to install a wealth of packages that aren’t available to install via the App Store.

One reason you might want to install Python via Brew is that it guarantees you’ll avoid the “Python command not found error” that can arise when installing with the official Python installer.

To install Python this way, you must first install Brew, which is done via a single command:

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

Once Brew is installed, you can then install Python with the command:

brew install python

After Python is installed, you then need to add it to your macOS $PATH. To do that, open your .bash_profile file with the command:

nano ~/.bash_profile

At the bottom of that file, add the following line:

export PATH=”$PATH:/Library/Frameworks/Python.framework/Versions/VERSION/bin”

Where VERSION is the version you’ve installed. For example, if you installed version 3.13, the line would be:

export PATH=”$PATH:/Library/Frameworks/Python.framework/Versions/3.13/bin”

Save and close the file.

Close and reopen the terminal and Python is ready to go.

Adding a Python-Ready IDE

Since you’re working on macOS, you might want to have a full-blown IDE that supports Python. One outstanding IDE is PyCharm, can be installed on Linux, macOS, and Windows. Do note that PyCharm isn’t free. You can purchase an organization license starting at $249.00 or an individual license starting at $99.00. Students, teachers, and open-source projects PyCharm can be used for free. Make sure to check out the pricing/feature matrix to learn more.

To install PyCharm on macOS, download the installer for your macOS architecture (either Intel or Apple Silicon) from the official PyCharm download page. Once the file has been downloaded, locate it in Finder, double-click it, and walk through the installation wizard.

You’ll find PyCharm listed in Launchpad. Click the Launchpad icon on your dock and search for the app. Click the launcher, agree to the license, and start your first project locally or remotely, via SSH. One thing to keep in mind is that to use the SSH connection, you have to have PyCharm installed on both local and remote machines. If you don’t have PyCharm installed on both machines, you’ll receive an error that the IDE on the remote machine is in an invalid state. You’ll also need to have a valid PyCharm Professional license for this to work.

I’ve found the SSH connection to be really handy, especially when I have projects I’ve already started on the Linux machines within my LAN. After launching an SSH connection, it does take some time to download the IDE backend, so be patient.

Once everything has been downloaded, you can start working on your remote project as though every file was saved locally (Figure 1).

Image

Figure 1 Screenshot

At this point, you should be good to go with Python on macOS.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.