How To Mac

How to Install Python on Mac

Written by John

Python is a general-purpose interpreted, object-oriented, interactive, and high-level programming language. It was created by Guido van Rossum in the late 1980s and first released in 1991. Python 2.0 was released in 2000, introducing new features including a garbage collection system and list comprehensions. In 2008, Python 3.0 was released and was completely backward-incompatible. However, many of the important features have been backported and are compatible with version 2.7.

Python 3 is highly readable and uses many English keywords for better understanding. It uses fewer punctuations and has fewer syntactical constructions. It is an easy language to learn for new programmers. Python 3 supports functional and structured programming methods, automatic garbage collection, and dynamic-type checking. It is easily integrated with other programming languages such as C, C++, and Java.

Python 3 as a beginner’s language is interactive and easy to read. The source code is easy to maintain. Python libraries are portable and can run with the same interface on a wide range of platforms such as Windows, Macintosh, and UNIX. Python is scalable and has better support for large programs. It supports the creation of GUI applications that can be ported to libraries and windows systems such as UNIX X Window System and Windows MFC. Python is extendable with low-level modules that enable programmers to make their tools more efficient through customization. It also has interfaces to all major databases.

Install Python with Homebrew?

Homebrew is a package manager that makes it easier to install software on macOS and Linux. You can save a lot of time finding and installing the right software for your operating system, by using a software package manager. Homebrew requires a compiler to install packages in macOS. You can install Xcode to get the compiler. Xcode is an integrated development environment (IDE) for macOS and has the tools needed to develop software for Apple operating systems.

When installing software using Homebrew, the package manager identifies and installs the right software for your particular system, depending on your specific setup. App installs can take anywhere between a few seconds and several minutes to complete.

The Problem With Python 2.7 on macOS

Python 2.7 comes pre-installed on macOS Monterey. However, the version is deprecated and has not been maintained after January 1, 2020. Hence, if you use Python 2.7 to build projects and any security issues arise with any of the packages you’re using, it would compromise your projects since nobody will be working on fixing your issues. It is essential to switch to Python 3 for a better experience and continued support.

The Beta 5 release of macOS Monterey 12 triggers an alert when you launch an app that uses Python 2.7. The alert indicates you to update the app to ensure smooth operation in future versions of macOS. This is a clear indication that Apple wants you to upgrade to Python 3 as Python 2 is no longer maintained.

How to Install Python 3 on macOS Monterey

We will install Python 3 on macOS Monterey and set up everything so that it becomes the default instead of Python 2 that is already pre-installed. Follow the steps below to install Python 3 on macOS Monterey

Step 1: Go to Applications > Utilities > Terminal.
Step 2: Check the version of Python by running the command: python --version. You should see the version of Python 2 installed on your macOS Monterey.

Python 2.7 on Mac

Step 3: In Terminal, type: python3. Xcode Command Line Developer Tools should be the first result to be returned. Click on it and click the Install button. Xcode takes some time to download. The command-line tools should be installed in a few minutes.

Install Command Line Developer Tool on Mac

Now, we need to get Python 3 from a package manager. There are two software package managers for macOS — MacPorts and Homebrew. We will use Homebrew to install Python 3 as it is more user-friendly. Homebrew requires a compiler to install packages.

Step 4: Now, we have to install Homebrew. Go to https://brew.sh. On the homepage, you should have the command to install Homebrew. Copy it, switch back to Terminal, paste the command, and press return.

Install Homebrew on macOS Monterey

The installation will begin and Homebrew will ask permission to create new directories. Press return and type your password to grant permission. The installation process will be completed and Homebrew will be installed on your macOS Monterey.

Step 5: To install Python 3, run the command: brew install python

Install Python 3.9 on macOS Monterey

How to Properly Set Up Python 3 on macOS Monterey

Python 3 is installed on your macOS. However, you need to properly set it up to make it the default instead of Python 2. Follow the steps below to properly set up Python 3 on your macOS Monterey.

Create a Bash File in Terminal

Step 1: If you’re not in your home directory, navigate to it by running: cd
Step 2: Type: nano ~/.bash to create a dot file, and open Text editor with nano command.

Edit Bash file with Nano

Step 3: Type: alias python=python3 to replace python to python3.
Step 4: Press Ctrl + O and press Enter to save your file, then press Ctrl + X to exit Nano Editor.
Step 5: Type: Source ~/.bash to load bash file in Terminal.

Replace Python 2.7 to Python 3 in Terminal

Check the version of Python by entering: python. This will confirm that Python 3 is the default version on your macOS Monterey.

Python 3 allows you to take full advantage of one of the most widely used programming languages on the web. By following the steps above, you can make it the default version to run on macOS Monterey.

Featured Posts
guest
0 Comments
Inline Feedbacks
View all comments