Set up Python3 on your macOS

Step 1. Get Apple’s Xcode

First, we need to install Apple’s Xcode command line tools which are needed by MacPorts; this is only an option for users who prefer to have a more traditional UNIX-like environment. The command line tools package provides many tools and utilities like make, gcc, perl, git, etc. Using the latest available version that will run on your OS is highly recommended.

Skip this step if you already have the command line tools package.

From now, we will use the Terminal (found in /Applications/Utilities) to install everything necessary to be able to configure Python in macOS. We can also use iTerm, if you prefer a more customizable terminal.

Launch the Terminal and type the following command:

The installer is finished after completed its own, then all the new commands like gcc, git, svn, rebase, make, ld, otool, nm, etc. will be available to be used. The entire command line tools packages gets installed under following path:

Step 2. Get macports

The highly recommended way to install MacPorts on macOS is by downloading the pkg for your OS version (Big Sur, Catalina, Mojave, High Sierra) and running the installer, following the instructions provided util completion.

MacPorts “selfupdate” command is run by the installer to ensure the latest release has been installed, however it is recommended to run the same command manually on a regular basis to maintain MacPorts with the latests updates. Since we will be using sudo, this will probably ask for your password. The command is used to interact with MacPorts, and it is used to update, install and manage the ports, the is used to update the local ports and is used to upgrade ports and their dependencies to the latest versions.

By default, upgrading ports in MacPorts does not remove the older versions. It is also highly recommended to remove old packages that have been left in the system, to save a little space.

Step 3. Get Python 3 via MacPorts

Once MacPorts is updated with the latest version, continue with Python installation and configuration. At the moment we show how to install Python 3.8, however the steps are compatible with other versions of Python 3.

If for a reason the installation gets corrupted or was interrupted, try cleaning the latest port for Python 3.8 and then execute again the port install.

Python 2.7 comes installed from macOS Sierra by default, , and from macOS Catalina we can find a reduced version of Ptyhon3, , so it will be necessary to configure the new version of MacPorts, , as the default. To achieve this, type:

Step 4. Installing X11

The X Window System is a system used to display windows, controls, and general user interface elements. The XQuartz project is an implementation of the X Window System on Mac OS X. It is an application that displays all the windows of applications that use X11.

X11 is generally the easiest way to do something that can be used on both OS X and Linux without additional code, so you will see a lot of ports in MacPorts using it. And this is the case for the IDLE for Python that has been installed, the X11 dependencies will be required to be able to run the editor in graphical mode. To install the latest X11 server on your OS, type:

At the end, the IDLE can be run like any other application.

My primary goal of doing this is the intellectual curiosity, the seduction of adventure.