Install RPi.GPIO Python Library

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. In order to use it you need to install the package as this isn’t currently included in the Debian Squeeze image.

UPDATE : The latest Raspbian SD card 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.5.5 (April 2014). If this version is updated you will need to make appropriate changes to the version number in the commands below.

To install it launch a command line (i.e. LXTerminal) and enter the following commands :

Step 1 – Download the library


Step 2 – Extract the archive to a new folder

tar zxf RPi.GPIO-0.5.5.tar.gz

Step 3 – Browse to the new directory

cd RPi.GPIO-0.5.5

Step 4 – Install the library

sudo python install

Step 5 – Remove the directory and its contents

cd ..
sudo rm -rf RPi.GPIO-0.5.5/

Step 6 – Delete the archive file

rm RPi.GPIO-0.5.5.tar.gz

This will now mean you can use the library within Python.

Example Usage

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)
This entry was posted in Python, Tutorials & Help and tagged , . Bookmark the permalink.

6 Responses to Install RPi.GPIO Python Library

  1. oluwatoyi says:

    Pls i followed the step above but am still getting no attribute setmode error…how do i correct this pls. thanks

    • Matt says:

      Use the latest version of Raspbian. This library is now installed by default so you do not need to install it manually.

  2. Ganesh says:

    Can you please explain the difference between GPIO.setmode(GPIO.BOARD) and GPIO.setmode(GPIO.BCM)?

    Thanks in advance!!

    • Matt says:

      BOARD allows you to use the physical pin numbers 1-26. BCM requires that you use the GPIO reference numbers. So physical Pin 8 (BOARD 8) is actually GPIO14 (BCM 14). Use the diagrams on my GPIO Header page to see the pin numbers against the GPIO references.

  3. Hello
    I’ve downloaded and tried to setup the library on raspberry b+ but it outputs this error
    fatal error Python.h file not existent
    What is this error?
    Thank you

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>