Python Development Environment

Raspbian comes with both Python 2 and 3 IDLE installed, they can be accessed through the top bar Menu > Programming > Python 2/3 (IDLE)

To create a new Python file in IDLE, use the File > New File menu.
Write some Python code and File > Save.
Then run your script with Run > Run Module (F5).

You can read more about Python on the Pi here

Virtual Environments

In order to create multiple isolated Python environments we can use virtualenv. An explanation on using virtualenv is available on the Python guide website.

We first need to globaly install virtualenv from pip:

> sudo pip install virtualenv

Then create a project folder and create a corresponding virtual environment:

> cd ~/path/to/my-project/
> virtualenv venv
[> virtualenv -p /usr/bin/python3 venv]  # to use a specific Python interpreter

Now that our virtual environment is created, we need to activate it:

[> cd /path/to/my-project]
> source venv/bin/activate

The name of the current virtual environment will now appear on the left of the prompt:

> (venv) pi@raspberrypi: ...

From that point, any package that we install using pip will be placed in the venv folder, isolated from the global Python installation. Like this:

> pip install requests

Once we are done working in the virtual environment, we deactivate it:

> deactivate