Python Installation

Python

Python is a high-level programming language that is widely used for software and web development, scripting, data analytics, reasearch, and scientific programming. To download and install the latest version of Python onto your computer, please follow the steps below for your respective operating system.

macOS / Mac OS X:

Download Python from the from the Python website & Install it in your machine.

  1. Open a web browser and go to the Python downloads page. python_downl
  2. Click on the link/button to download Python 3.9 or later. python_downl
  3. Once dowloaded, open the .pkg installer in your Downloads folder and follow the installation instructions (we recommend to leave all of the default settings as they are). Enter your password if prompted.Mac Installer

After the installation is finished, open the Terminal application of macOS. You can press Command + Space Bar, this will open up the Spotlight Search Bar and you will then type the word terminal and press enter/return when the application pops up. You can also go to ApplicationUtilities and search for the terminal. A bash terminal will open where you can enter commands and do cool things in your computer.

Once you have it opened, let’s proceed with the basics. Enter the following command in the terminal, and then press enter/return:

pwd

You should now see the working directory or main folder where everything that exists within your username will come up. Next, type the command below and press enter/return:

python3

You should see the Python version you have installed (i.e. 3.x), and you can now run Python code using your terminal. Print “Hello world” using the print command. Type print("Hello World!")

Mac Terminal

You can type exit() in your terminal to exit out of Python and then close the terminal window.

Setting Python 3 as the default version in Mac OS

If an older version of python already exists in your computer, you can change the alias of the python command in your bash terminal to refer to the python 3.x version you just installed.

To do this, you will need to follow the following steps in your terminal.

  1. Open your terminal again. Click on the Spotlight Search button, type terminal, and then press enter/return.
  2. Type nano ~/.bash_profile
  3. Add the following in a new line:
alias python="python3"
  1. Press Control + o and then press enter/return
  2. Press Control + x to exit nano

If you close that terminal and then open a new one, you can now use the “python” command and it should invoke the latest version of python3.

Windows

Download Python from the from the Python website & Install it in your machine.

  1. Open a web browser and go to the Python downloads page for Windows. Underneath the Python Releases for Windows find Latest Python 3 Release – Python 3.8.x (latest stable release at the time of writing, is Python 3.9.2):Windows Python releases
  2. Click on the latest stable release near the top of the page. Then on the release page, scroll down to Files and click on Windows x86-64 executable installer for 64-bit or Windows x86 executable installer for 32-bit. If you are unsure about your operating system, please check before downloading a version of Python.Windows Python bit installers
  3. Once dowloaded, open the .exe installer in your Downloads folder and follow the installation instructions. Make sure to check “Add Python 3.x to PATH” or otherwise you will have to do it explicitly. Click “Install Now” and after doing so, it will start installing Python on Windows.Windows install screen
  4. After the installation is complete, click Close. The latest version of Python should now be installed. Windows install complete

You can use the Command Prompt in Windows to invoke Python. Go to the start menu and open the Command Prompt application. Type python in the command prompt to confirm that it was installed correctly. Then try entering the command to print(“Hello World!”) to run your first line of code.

Windows Commnand Prompt

Linux

Python comes pre-installed in most Linux machines so we will first be checking for the version we have, if any, and then updating it to the latest stable release.

Debian / Ubuntu (apt-get)

To see which version of Python is installed, open a terminal and run:

python3 --version

If you are using Ubuntu 18.10 or newer, then you can easily install the latest version of Python 3 with the following commands:

sudo apt-get update
sudo apt-get install python3

The latest version of Python language should now be installed on your Linux system, and you can confirm it by running the previous command again:

python3 --version

Fedora (dnf/yum)

Other Linux systems may also have Python pre-installed. You can update to the latest version using your Linux distribution’s package manager. On Fedora, use the command:

$ sudo dnf install python3

Open a command prompt or shell and run the following command to verify that Python was installed correctly.

$ python3 --version
Python 3.7.5

How to set Python 3 as the default version in Linux?

You can set python3 as the default Python of your Linux system, so that whenever you enter “python” anywhere in the terminal it always executes python3. Open the terminal and type the following command

vim ~/.bash_profile

Press the letter i and then add the following command in a new line.

alias python="python3"

Then you will press the Escape buttom in your keyboard, the type :wq and then press Enter. Close and restart your Terminal, and now, any code executed in your terminal will automatically use python3 as the default version.

Type python in your terminal and then print(“Hello world”).

Linux Terminal