Newby Coder header banner

Python Setup

Python comes shipped with OS like ubuntu and macOS

Check python version with

python -V

Check python 3 version(in case above command shows a Python 2 version) with

python3 -V

Contents :

Python pip

PIP is a package manager for Python packages, or modules

Modules are Python code libraries that can be included in a program, like http, json

A package contains all the files required for a module

pip should get installed along-with Python 2 >=2.7.9 or Python 3 >=3.4 versions

Following command can be used to check if pip is installed (and/or included in system PATH)

pip -V

It prints out the pip version if pip is found

In case not found, check for Python 3 pip

pip3 -V

Installing Python in Linux/Ubuntu

Unix environments come pre-installed with Python

Check if Python is installed with python -V or python3 -V

Python can be installed with

sudo apt-get update
sudo apt-get install python

Open a new terminal and try running python -V or python3 -V (for python 3)

Installing python 3 in Linux / Ubuntu

Python 3.6 can be installed with

sudo apt-get update
sudo apt-get install python3.6

Installing pip in Linux / Ubuntu

Check if pip is installed with pip -V or pip3 -V

pip can be installed with

sudo apt-get install python-pip

pip works with Python versions 2.7, 3.5, 3.6, 3.7, 3.8 and also PyPy

Installing pip for python 3+ in Linux / Ubuntu

sudo apt-get install python3-pip

Upgrading pip in Linux / Ubuntu

Following command can be used to upgrade pip

pip install -U pip

Installing Python in Mac

Mac environments come pre-installed with Python (probably python 2.7)

Check for python version with python -V or python3 -V

Check below in case you want to install python 3

Installing python 3 in Mac OS

Go to https://www.python.org and hover over Downloads tab

There should be a download link of a recent stable Python version

cm-python-download

Once downloaded, open it and follow installation steps

Installing python 2 in Mac OS

Visit https://www.python.org/downloads/mac-osx/ and select a version (like Python 2.7.18), preferably a 64-bit installer

Download it and open (both .dmg and .pkg files shouldn't require commands from the user to install)

Follow installation steps


Installing pip in Mac OS

pip should be already installed in case one of Python 2 >=2.7.9 or Python 3 >=3.4 versions is installed

Check if pip is installed with pip -V or pip3 -V

To install pip, open Terminal and download a file get-pip.py as follows :

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

After downloading, run following command from the directory where it is downloaded

python get-pip.py

pip works with Python versions 2.7, 3.5, 3.6, 3.7, 3.8 and also PyPy

Above commands were taken from Pip website

Upgrading pip in Mac OS

Following command can be used to upgrade pip

pip install -U pip

Installing Python 3 / 2.7 in Windows

Check if python is installed with python -V or python3 -V

In case not installed or to install a different version :

Download Python 3+ in windows

Go to official Python website https://www.python.org and hover over Downloads tab to get download link for a recent stable version

Download Python 2.7 in Windows

Go to https://www.python.org/downloads/windows/ to get Python 2.7 or an older version


Installation

Download and double-click the file to install

After installing, open Run using the β€˜windows key + r’ keyboard shortcut and type cmd and press enter to open command prompt

Check for python version with command python -V or python3 -V

In case python command is not found, follow following steps to add Python to system PATH

System PATH is an environment variable which contains a list of paths (or locations like C:\Windows

This is used by the Command Prompt and number of other programs running in the System, to find for libraries or executables (like Python)

If the location of folder containg Python.exe is present in PATH, then Python can be run from the command prompt without requiring to enter full path


Setting up PATH variable for Python in Windows

For Python 2.7 versions, add the following directories to PATH:

C:\Python27\
    C:\Python27\Scripts\
    C:\PYTHON27\DLLs\
    C:\PYTHON27\LIB\ 

For Python 3.5+ versions, add the following directories to PATH:

C:\Python27\
    C:\Python27\Scripts\
    C:\PYTHON27\DLLs\
    C:\PYTHON27\LIB\ 

Installing pip in Windows

pip should be already installed in case one of Python 2 >=2.7.9 or Python 3 >=3.4 versions is installed

Check if pip is installed with pip -V or pip3 -V commands in Command Prompt

To install pip, open Terminal and download a file get-pip.py with following command :

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

After downloading, run following command from the directory where it is downloaded

python get-pip.py

pip works with Python versions 2.7, 3.5, 3.6, 3.7, 3.8 and also PyPy

Above commands were taken from pip website

Upgrading pip in Windows

Following command can be used to upgrade pip in windows

python -m pip install -U pip

Or for python 3 :

python3 -m pip install -U pip