Before you start coding with Python, you have to install Python 3 on your machine. Python 3 is what acts as the interpreter for python scripts, so the code you write can be run.
You can click the table of contents links below to jump straight to your operating system. Okay, let's go...
Installing Python 3 on the Windows Operating System
In this part we'll install Python 3 for the Windows operating system. If you're on Linux, skip ahead to the bottom.
There are a few ways to install Python 3 on a Windows machine
- Using the installer downloaded from the Python community website
- Using WSL (Windows Subsystem for Linux)
The first way is probably clear by now, and we'll go further into it after this. For the second way, you can roughly follow the steps for Installing Python 3 on the Linux (Ubuntu) operating system further below.
Step 1: Download the Python installer
To download the installer, follow the steps below:
- Open your browser and go to the Python 3 for Windows download page
- Under "Python Releases for Windows" click the link to download the latest version of Python 3 (Latest Python 3 Release - Python 3.x.x). At the time of writing the version is Python 3.9.1
- Next you'll be taken to the download page. Scroll down until you find "Windows installer"
- According to your windows version, choose "Windows installer (32-bit)" if you're on a 32-bit machine or "Windows installer (64-bit)" for a 64-bit machine.
- The download then starts, wait a moment.
The python.org download page carries the list of installation file releases for Windows, complete for both 32-bit and 64-bit architectures.
๐ท Illustration: the python.org web page showing the list of 32-bit and 64-bit Windows installer download links.
Step 2: Installing Python 3
Once the installer finishes downloading, double-click the downloaded file to open the Python 3 installation window. Make sure the Add Python to PATH option is checked at the bottom so the Python command can be called straight from the terminal.
๐ท Illustration: the opening Python 3 installation window on Windows, with the Install Now button and the Add Python to PATH checkbox.
Go straight ahead and click "Install Now". An installation progress window then appears. How long it takes depends on your machine, probably no more than 10 minutes.
When the installation finishes, try pressing the start menu in the bottom left corner, then search for "python".
๐ท Illustration: Windows start menu search results showing the Python 3 app along with the IDLE module already installed.
If the Python 3 app shows up in those search results, the installation worked. Yeyy congratulations!
Step 3: Opening the Python 3 Interpreter
There are 2 ways to reach the Python 3 interpreter on windows
- Click the Python 3 app icon
- Using CMD or Powershell
The first way probably doesn't need a long explanation anymore. You can just click the search result from the previous step. A terminal window made for Python opens right away, complete with the three-angle-bracket prompt (>>>).
๐ท Illustration: the interactive Python 3 console window on Windows with the three-angle-bracket prompt ready to take commands.
The other way is using CMD or Powershell as the terminal interface for Python.
First you have to open CMD or Powershell. Do it by pressing the key combination Windows + R, and a Run dialog box comes out at the bottom left of the screen.
Next type CMD or Powershell in the field provided, then press OK.
๐ท Illustration: the Run dialog box on Windows with the CMD keyword typed into the opening field.
This Command Prompt window shows the Windows command line with a blinking cursor ready to take instructions.
๐ท Illustration: the Command Prompt window interface showing the active user directory path line.
The last step is typing the command "py" into CMD (without the quotation marks) then pressing enter. The moment enter is pressed, the CMD session turns into an interactive Python interpreter with a >>> prompt.
๐ท Illustration: the command line in Windows Command Prompt turning into an interactive Python 3 session.
Okay... Installing Python 3 on Windows is done. Always remember how to open Python, because this is your main tool for learning the language. If you forget, come back to this piece, hehe...
Installing Python 3 on the Linux Operating System
Most Linux systems these days already have Python installed, so we don't need to install anything.
Now we'll check whether python is installed. First open your own terminal by pressing ctrl+alt+t.
Once the terminal window is open, type the following command then press enter.
python3 # or
python
If you make it into the Python 3 interpreter (it looks like the output below), python is already installed on your machine.
Look at the python version that shows up. Make sure it's on 3.x.x
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
But... if what comes out isn't like the above, Python isn't installed yet. You can move on to the next step.
Once the installation finishes you can run the command above again to confirm python 3 is installed.
Pick the one that matches your distribution.
Ubuntu and Its Derivatives
Run this command in the terminal to install python3 and pip3.
sudo apt update
sudo apt install python3 python3-pip
Arch/Manjaro and Its Derivatives
pacman -S python
Fedora and Its Derivatives
sudo dnf install python3
Wrapping Up
That's it for this tutorial, hope it helps :) Next time we'll play with the python 3 interpreter first.
See ya...