Python Installation
Before you start writing Python programs, you'll need to download and install a copy of Python (unless you already have it). Here's how.
There are many ways to download and install Python. This can depend on your operating system, and whether you use a package manager or not.
And if you're running a Linux or Mac machine, you may already have Python installed. However, it's a good idea to install the most recent version (see below for more info about this).
To keep things simple, here are the basic steps involved in downloading and installing Python (without using a package manager). If you prefer to use a package manager, skip down to Installation with a Package Manager.
-
Download Python
You can download Python from the official Python download page.
Choose the latest version (3.x) unless you have a reason to use an earlier version. This tutorial uses version 3.6.1.
-
Install Python
The exact steps here will depend on your operating system.
Windows and macOS
In Windows and macOS, double-click on the installer and follow the prompts.
Linux
In Linux, you can use the terminal to extract the installation files and install Python. Something like this:
- Untar the .tgz file:
- Change to the directory to where the files were untarred to. For example:
- Install Python:
- Untar the .tgz file:
-
Check your Installation
To check that Python 3 was installed, open your terminal (or command prompt on Windows), and type the following:
If this doesn't work, try it without the 3:
Anyway, running this code will launch Python. So if Python 3 was successfully installed, you'll see something like this:
Python has now been installed, and it is now running on your machine. You can now start writing Python programs immediately!
Installation with a Package Manager
Some developers use a package manager to download and install their software. If your system has a package manager, you can use it to install Python instead of using the above steps.
A package manager enables you to download and install Python with one or two commands. For example, on a Mac you can install Python using Homebrew using the following commands (assumes you have Homebrew installed):
On Linux machines the exact commands you use will depend on your Linux flavor and its package manager.
Here's the command you can use with Ubuntu 16.10 and later:
Of course, you'll need to ensure you're installing the most recent version of Python.
Isn't Python Preinstalled?
Some operating systems come preinstalled with Python. In particular, most Macs and Linux machines will already have some version of Python installed.
However, even if your computer already has Python, you might want to install the latest copy before you continue with this tutorial. In particular, if you have Python 2 installed, you might want to install Python 3.
The reason I say that is, when Python version 3 came along, it was significantly different to its previous version. It was basically re-written to address many issues that had been identified in version 2 over the years. As a result, some code written using Python 2 won't work in Python 3.
When I refer to Python 2 and 3, I mean any version of those major releases (eg, Python 2.7, Python 3.6.1, etc).