If you'd rather have Python 3, just replace python with python3.
To install Python 2.7.x, just type: $ brew install python You can install a few different versions of Python, including 2.7.x and 3.5.x. Now that you know what Homebrew is and have it installed, we can get on to installing Python. To install Homebrew, just follow the instructions on their website (which I linked to at the beginning of this section). For example, here are just a few things I've installed with it: android-sdk, go, mongodb, sqlite, git, imagemagick, lua, python3. It makes it much easier to install all the various tools you might need. Homebrew lets you install, update, and uninstall packages from the command line, just like apt-get does for Ubuntu. According to their website, Homebrew is "the missing package manager for OS X". Install Python with Homebrewįirst of all, if you don't know what Homebrew is and you use Mac OSX, you should.
Now, keep in mind that Mac OSX (10.8) already comes with Python 2.7 pre-installed, so these instructions will only really be helpful if you need to upgrade versions or need a better way to manage installations (like with Homebrew). Instructions for installing Python 2 and 3 are different in most cases (but not by much), so make sure you're paying attention to which version you need installed. These are the most commons you'll encounter, and each method has its own purpose, all of which I'll detail in the sections below. I figured it would be helpful to detail a few of the easiest ways to install Python, including the following: We can confirm if the new version of Python is successfully installed or not by checking the Python version using the same above two commands.As with just about any open source software package, there are quite a few ways to install Python on Mac OSX.
We can download the installer and update or install the desired version using the Python installer. We can check the versions of Python 2 and Python 3 installed on Mac using the following commands.Īfter checking the version, the next step is to check if any new version is available on the official website. brew install Python Using Python Installer for macOSīefore updating or installing Python on Mac using the Python installer, the first step is to check the installed version of Python on Mac. Using the following command, we can also install Python 2 on macOS. In case we have to use Python 2 to run a program, we can do so by indicating the default macOS Python binary path /usr/bin/python/ at the start of the code file, as shown below. echo "alias python=/usr/local/bin/python3.7" > ~/.bashrc Therefore, we can use an alias that will point to the Python version installed by Homebrew to run the Python scripts. cp /usr/local/bin/python3 /usr/local/bin/pythonīut the problem with the above method is that it will be a problem to run some legacy code using Python 2 in the future. Once Python 3 is installed, we can set is as default to run the programs, using the following command. We can also update the Python 3 version from 3.x to 3.y using the following command on the terminal. Once we have Homebrew, we can easily install Python on macOS using the following command on the terminal. If Homebrew is not installed on your Mac, you can install it from here. It helps in installing and updating the software through the terminal. Homebrew is an open-source package manager software for macOS and Linux.
And we can easily update Python on macOS using Homebrew. Therefore another way to update Python to the latest version is by using a single command.
We will also discuss how to install the latest version of Python 3 or Python 2 on Mac.Īlthough the easiest way to update or install the latest version of Python on Mac is by using Python’s official website, we will have to check for future updates manually by checking the site again and again.
In this tutorial, we will discuss different methods to update Python on Mac.