Installing Python
5 minute read
Abstract
This tutorial teaches how to install Python on Windows 10. It can be similarly installed also on macOS and Linux.
Contents
Keywords: python
Windows
Click the following image to be redirected to a 2-minute YouTube walkthrough.
-
First, open the url https://www.python.org/downloads/ in any web browser.
-
As of June 2021, the latest version of Python is
3.9.6
. You may see a different number. We recommend you use the newest official version which is provided to you by simply clicking the button under “Download the latest version for Windows”. -
Once the download has completed, open the file by clicking on it in your Downloads pane.
-
Be sure to check the box that reads “Add Python x.x to PATH”. This will allow you to run commands from the terminal/command prompt.
-
Click “Install Now”. The default options that entail this selection are appropriate.
- The UAC prompt will pop up. UAC stands for “User Account Control” and exists so that the computer will not have unauthorized changes performed on it. Click “Yes” because Python is safe. School-issued computers may ask for an administrator password, so contact your IT department or professor.
-
The installation will take some time.
-
If the setup was successful, then it will say so. Click “Close”.
-
Click the “Type here to search” box in the bottom-left of the screen, type “cmd”, and press Enter.
- An alternative method is to press the Windows key and the “R” key at the same time, type “cmd”, and press Enter. This is convenient for those who like to use the keyboard.
-
Type
python --version
and the output should read “Python x.x.x”; as long as it is the latest version from the website, congratulations. Python is installed on the computer.
Mac
Click the following image to be redirected to a 5-minute YouTube walkthrough. (Yes, Mac’s video is a little longer, but do not fret! You can skip to the 1:00 minute mark if you are in a hurry.)
-
First, open the url https://www.python.org/downloads/ in any web browser.
-
Underneath
Download the latest version for Mac OS X
, there should be a yellow button that readsDownload Python x.x.x
. Click on it, and the download should commence. -
Once the download finishes, open it by clicking on it. The installer will open. Click
Continue
, clickContinue
again, and clickContinue
again. Read the agreements. -
Click
Agree
.- If you want to check how much free storage you have on your computer, click the Apple icon in the top left of your computer. Click
About This Mac
and then click onStorage
. As of July 2021, Python takes ~120 MB of space. Remember that 1 GB = 1000 MB.
- If you want to check how much free storage you have on your computer, click the Apple icon in the top left of your computer. Click
-
Click
Install
. Enter your password and press Enter. The installation will take a while. -
A Finder window will open. You can close it as it is unnecessary. Click
Close
in the bottom-right of the installer. ClickMove to Trash
because you do not need the installer anymore. -
Next confirm that Python installed correctly. Click the magnifying glass in the top-right of your screen and then type
terminal
into Spotlight Search. Double-clickTerminal
.- The terminal will be used frequently. Consider keeping it in the dock for convenience. Click and hold the Terminal in the dock, go to
Options
, and clickKeep in Dock
.
- The terminal will be used frequently. Consider keeping it in the dock for convenience. Click and hold the Terminal in the dock, go to
-
Type
python3 --version
into the terminal and press Enter. It should output the latest version of Python. Congratulations!
Linux
Click the following image to be redirected to a 9-minute YouTube walkthrough. (Linux’s tutorial is the longest, but it is worth it.) This tutorial uses Ubuntu, but it should work on other Linux distros, as well.
- Naturally we recommend that you read all of the licensing information.
-
First, open the url https://www.python.org/downloads/ in any web browser.
-
Look at the latest version. It is on the yellow button:
Download Python x.x.x
. You do not need to click this button. Remember this version number. -
Open a terminal by pressing the Windows key or by clicking the grid on the bottom left of your screen. Type
terminal
. Click on theTerminal
result that appears. -
Next, prepare your system:
Note: If you want to check how much disk space you have, you can use
$ df -h /
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1s5s1 1.8Ti 14Gi 387Gi 4% 553757 19538475003 0% /
The value under Avail will be your available space. Make sure you have sufficient space.
$ sudo apt-get update
$ sudo apt install -y wget curl
$ sudo apt install -y openssl libssl-dev
$ sudo apt install -y build-essential zlib1g-dev libncurses5-dev
$ sudo apt install -y libgdbm-dev libnss3-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev
-
After this finishes, type
cd /opt
and press Enter. Then, remember which version you read on the Python webpage (the latest version) and add it as environment variablePV
to your terminal so we can more easily execute commands that include the version number. Type:$ PV=3.9.6 $ sudo wget https://www.python.org/ftp/python/$PV/Python-$PV.tgz $ sudo tar xzvf Python-$PV.tgz $ cd Python-$PV $ ./configure --enable-optimizations $ make $ sudo make altinstall
-
Confirm Python’s successful installation by typing
pythonx.x --version
; be sure to replace x.x with the first two numbers of the version number. It should output the latest version number. Congratulations!
Python venv
Before you install packages, you need to create a Python venv in your local environment. We typically do this with
$ python3.9 -m venv ~/ENV3
$ source ~/ENV3/bin/activate
or for Windows executed in git bash
$ python -m venv ~/ENV3
$ source ~/ENV3/Scripts/activate
Troubleshooting
Incorrect Python Version on Command Prompt (Windows)
If the Windows computer has previously installed an older version of Python, running python --version
on Command Prompt may output the previously installed older version. Typing python3 --version
may output the correct, latest version.