The objective of this tutorial is to install Python and run it with virtual environment.

Prerequisites

Installation

Usually Python is already installed with the Raspbian image.

Check install:

python --version

Otherwise you can install it

apt-get update
apt-get install build-essential python-dev

Install PIP

PIP is a package management system used to install and manage some packages written in Python.

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

See more here

Create VirtualEnv (optional)

A Virtual Environment is useful to keep the dependencies required by different projects.

Note: virtualenv includes PIP

Installation

sudo pip install virtualenv
Create a workspace directory for the Python version.

Example:

mkdir -p ~/workspace/venv2.7

Example:

virtualenv -p /usr/bin/python2.7 ~/workspace/venv2.7/

Start the virtual environment.

source ~/workspace/venv2.7/bin/activate

You can now install all packages you need into your isolated environment. Example:

pip install requests

See more here