Install RPi.GPIO Library In Raspbian

The RPi.GPIO Python library allows you to easily configure and read-write the input/output pins on the Pi’s GPIO header within a Python script.

This article is an updated version to take into account changes in the RPi.GPIO library and the release of the Raspbian SD card image.

UPDATE : The latest Raspbian (2012-09-18-wheezy-raspbian) image includes the RPi.GPIO library already installed so if you are using that image you do not need to bother reading the rest of this article.

The package is available from and the current version is 0.3.1a. If this version is updated you will need to make appropriate changes to the version number in the commands below.

The latest packages are available on the RPi.GPIO downloads page.

To install it you need to enter some command line instructions. You can either use the command prompt after you have logged into your Pi or use a command line tool (i.e. LXTerminal) once you have entered the graphical interface (by typing startx).

Step 1 – Download the library

Take a look at the downloads page and select a suitable package. I have selected the “Raspbian package for Python 2″. Use wget to download the package to your Raspberry Pi.


Step 2 – Install the library

The following command will use the dpkg utility to install the package.

sudo dpkg -i python-rpi.gpio_0.3.1a-1_armhf.deb

That’s all there is to it! This will now mean you can use the library within Python.

Example Usage

Copy the following script into a text file called “” :

import RPi.GPIO as GPIO

# to use Raspberry Pi board pin numbers

# set up the GPIO channels - one input and one output
GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.OUT)

# input from pin 11
input_value = GPIO.input(11)

# output to pin 12
GPIO.output(12, GPIO.HIGH)

# the same script as above but using BCM GPIO 00..nn numbers
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
input_value = GPIO.input(17)
GPIO.output(18, GPIO.HIGH)

To run this script you can use the following command :

sudo python

You need to include “sudo” in front of this command as the GPIO library requires root privileges.

This entry was posted in Python, Raspbian, Tutorials & Help and tagged , , . Bookmark the permalink.

2 Responses to Install RPi.GPIO Library In Raspbian

  1. Thank you for this – I’m at the stage where I haven’t a clue how the GPIO works, I just want to _use_ the thing ;-)

  2. James says:

    I know this article is a few weeks old, but it’s worth noting that adafruit’s RPi distro Occidentalis comes with GPIO, I2C, SSH etc support enabled. It looks like a good distro for anyone doing I/O work.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>