Skip to content

Installing Python

Ahrar Monsur edited this page Jun 20, 2018 · 5 revisions

This is a detailed guide on installing Python 3 on your computer. Additional instructions are also provided on how to install useful packages and tools to be used with Python.

Installing python3

On Mac OS X

  1. First, you must install the Homebrew package manager. Open a terminal and run

     ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. Insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file

     export PATH=/usr/local/bin:/usr/local/sbin:$PATH
    
  3. Finally, run the homebrew command to install python

     brew install python
    

Note: The python installation will also use the pip python package manager. We will use this to install the python utilities and libraries that we will need.

On Linux

Most modern linux distributions come with python preinstalled.

  1. You can check if you have Python 3 installed opening a terminla instance and running python3 --version. If a version 3.x.x is returned, it means you have python3 installed.

  2. If you receive an error or a message saying python3 does not exists as a command, you can install it by running

     sudo apt-get install python3
    

On Windows

  1. Obtain the Windows python installer from the python downloads page
  2. Navigate to where the executable was downloaded and run the installer. The file should be named something similar to python-3.x.x.exe
  3. To make sure of the python package manager pip, you will first need to ensure that python has been added to your computer's PATH variable. To do this, do the following:
    1. Open the Start Menu and search for 'My Computer' on Windows 7, or 'This PC' on Windows 8/10

    2. Right click on the icon and select 'Properties'

    3. In the window that pops up, select 'Advanced system settings'

    4. In the new window, click the 'Environment Variables' button

    5. Under the 'User variables' section, select the 'Path' variable, and click the 'Edit' button. In the pop up window, go to the end of the 'Variable value' field, and add the following path to the old value, separated by a semicolon (;). If the 'Path' variable doesn't exists, then click the 'New' button and create it with the same path

      C:\Users\[YOUR USERNAME]\AppData\Local\Programs\Python\[YOUR PYTHON VERSION]\Scripts

      NOTE: ensure the values in [...] in the path is substituted by the appropriate values on your system

Installing virtualenv

Virtualenv a tool to create isolated Python environments (virtual environments). This package allows us to manage dependencies in a sandbox on a per-project basis, thereby not polluting the system-level installation. Also, virtualenv allows us to conveniently report the dependency chain, selectively remove dependencies, and even delete all dependencies by simply deleting the virtualenv directory. To install virtualenv:

  1. Open a terminal instance on Mac/Linux, or run cmd.exe on Windows

  2. Upgrage pip and install virtualenv

     pip install --upgrade pip
     pip install virtualenv