Installing Python

In this chapter, you will learn how to install Python on MacOS, Window, and Linux. We will look at multiple ways to install Python on your platform, and discuss what I think is the best option to choose from. Most of the times, it's not advisable to install Python by using the official installer from the python.org website. Instead, it's better to install the version packaged by your operating system. The advantage to installing the Python version supplied by your operating system, is that you'll get automatic updates.

If you don't feel like installing Python, or you are unable to install it for whatever reason, I'll offer an alternative too: you can use Python right from your browser; no installation necessary! It's a nice way to try Python and see if it's for you, without the hassle of installation. The on-line option will give you a fully fledged Python version, so don't have to be affraid your missing something. Much of what you'll learn on this site, can be done in the on-line version as well.

Windows

There are three ways to install Python on Windows.

Using The Microsoft Store

Microsoft hosts a community release of Python 3 in the Microsoft Store. This is the recommended way to install Python: it handles updates automatically and can be uninstalled easily too.

To install it:

With the Python.org installer

You can download a Python installer from the official Python download website too. This method does not give you automatic updates, and I would recommend it only if you don’t have access to the Microsoft store.

On most versions of MacOS before Catalina, a distribution of Python is already included. Unfortunately, it’s almost certainly an old version, Python 2.7. Luckily, there are several ways to install Python 3 on a Mac.

Install Python inside WSL

If you're familiar with Windows Subsystem For Linux, you may want to consider that option too. Especially if your product will end up running on a Linux machine! To install Python in WSL, simply follow the Linux installation instructions below.

MacOS

On your Mac, there are two methods of installation.

Homebrew

First and foremost, I recommend looking into Homebrew. It allows you to easily install almost anything. The added benefit is that it’s also easy to upgrade to newer versions later on.

Once you are up and running with homebrew, installing Python is as easy as:

$ brew install python

Official installer

Alternatively, you can download an installer from the Python download website. The downside to this approach is that you won't get automatic updates.

Linux

There are several ways to install Python on Linux, that is, if you need to install it at all!

Check What's Installed

Most Linux distributions include Python. Many will include both Python 2 and Python 3.

If you enter python --version on the command line, you’ll see the version number. It’s probably version 2.7:

$ python --version
Python 2.7.16

Now try python3 --version. If you get a “command not found,” you need to install Python 3. If your output looks like this, you're in luck:

$ python3 --version
Python 3.7.6

Installing using a packages manager

Depending on the distribution of Linux you are running, you can install python with either Yum, APT, etcetera. You'll need to find out for your specific Linux distribution which package manager is used, and how to use it.

Homebrew

Another interesting option for Linux is using Homebrew. That’s right, the package manager for Macs also works on Linux.

The major advantages of using Homebrew:

  • You’ll get the latest version of Python, instead of the version your OS shipped with
  • You don't need root access to your system. Packages are installed in your home directory

I find myself using Homebrew more and more while working under Linux — give it a try!


If you liked this page, please share it with a fellow learner: