Install Python on Mac Operating System
Apr 01, 2019 | Updated: Apr 01, 2019

By default, Mac OS comes with pre-installed Python version 2.7.x. However, for development purpose you need an updated version of Python.

There are more than one ways of installing Python on Mac OS but I recommend to install Python via Homebrew (The missing package manager for Mac OS). It makes the installation process easier and simpler for installing any software packages that Apple didn't.

In this article I will show how to install latest version of Python on Mac OS with Homebrew. If you are a Windows user and want to install the latest version of Python then check my another article Install Python on Windows Operating System.


Check Python version

It's always better to check whether Python is already installed or not before going for a fresh installation. As Mac Os comes with pre-installed Python, so if you check the version in your terminal by $ python --version command you should see the following.

$ python --version
Python 2.7.10

Now, you should also check whether Python3 is already installed by $ python3 --version command in your terminal. If not installed you will get an error. Even Python3 is already installed but not the current version, then you can also install the current version together with previously installed Python3 if you want (that's not a problem). You can keep multiple version of Python on Mac OS.


Install Homebrew

Before installing Homebrew, you need to install Apple's Xcode (Xcode package includes everything you need to create apps for all Apple platforms). Xcode is a large package so it might take a while to install (depending on your internet speed). To install Xcode run the following command in your terminal.

$ xcode-select --install

Next, install Homebrew by running the following command in your terminal prompt. It's a bit long command. However, you can easily copy the command the from Homebrew website and paste it in your terminal.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To check whether Homebrew installed correctly or not, run the following command in your terminal prompt.

$ brew doctor
Your system is ready to brew.

Cool! Your system is ready to brew. Now you are all set to install software packages via Homebrew. Note that, Homebrew installs software you need that Apple (or your Linux system) didn’t.

To install software package via Homebrew, run the following command.

$ brew install [software-package-name]

To upgrade software package via Homebrew, run the following command.

$ brew upgrade [software-package-name]

To uninstall software package via Homebrew, run the following command.

$ brew uninstall [software-package-name]

To list out number of software packages installed via Homebrew, run the following command.

$ brew list

To update Homebrew itself run the following command. It's better to update Homebrew first before installing and upgrading any software packages.

$ brew update

To read the help documentation about Homebrew commands, run the following command.

$ brew help


Instal Python via Homebrew

To install the latest version of python, just run the following command in your terminal prompt.

$ brew install python3

That's it! Now check the python version just installed run the following command.

$ python3 --version
Python 3.7.2

All set! You can now open the Python3 shell by running the $ python3 command and start python coding, like below.

$ python3
Python 3.7.2 (default, Jan 13 2019, 12:50:01) 
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

To exit from the python3 shell type exit() and press Enter. Alternatively, you can press Ctrl + D together to exit form the shell.


Summary

There are multiple approaches to install Python. I have presented the approach I found simpler. However, I strongly recommend to install Python via Homebrew. By following this article you can install Python on your computer.

Happy Python coding!


Comments

You are welcome to write comments, suggestions, corrections, or any queries related to the article. Your comments may take some time to be appeared. Please be aware that any irrelevant comments will be deleted. Thanks for your understanding, and your respectful & relevant comments!