Close Menu
    Facebook X (Twitter) Instagram Pinterest YouTube
    Trending
    • Disable SSH Password Login on Raspberry Pi
    • Elecrow Meteor IPS Touchscreen with RGB LEDs
    • Pi Pico Pinout Display on the Command Line
    • How to Add a Raspberry Pi Pico Reset Button
    • Pi Pico Onboard LED
    • Pi Pico W Pinout and Power Pins
    • CrowPi L Raspberry Pi Laptop and Learning Platform
    • Pi Pico W Launched
    Mastodon YouTube Facebook Instagram Pinterest RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        February 16, 2024

        Disable SSH Password Login on Raspberry Pi

        December 23, 2022

        How to Add a Raspberry Pi Pico Reset Button

        November 20, 2022

        Pi Pico Onboard LED

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Python»Install RPi.GPIO Python Library
      BerryClip Plus

      Install RPi.GPIO Python Library

      17
      By Matt on May 30, 2012 Python, Tutorials & Help

      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. Thankfully this library is now including in the standard Raspbian image available from the Foundations Download Page.

      If you are using a fresh image you don’t need to install it but I’ve kept the instructions here in case you ever want to try a manually installation.

      Method 1 – Install from repository

      If the package exists in the Raspbian repository is can be installed using apt-get. First you need to update the available package versions :

      sudo apt-get update

      Then attempt to install the RPi.GPIO package :

      sudo apt-get install rpi.gpio

      If it isn’t already installed it will be installed. If it is already installed it will be upgraded if a newer version is available.

      Method 2 – Manual Installation

      The package is available from http://pypi.python.org/pypi/RPi.GPIO and the current version is 0.5.11 (February 2015). If this version is updated you will need to make appropriate changes to the version number in the commands below.

      Step 1 – Download the library

      wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz

      Step 2 – Extract the archive to a new folder

      tar -xvf RPi.GPIO-0.5.11.tar.gz

      Step 3 – Browse to the new directory

      cd RPi.GPIO-0.5.11

      Step 4 – Install the library

      sudo python setup.py install

      Step 5 – Remove the directory and archive file

      cd ~
      sudo rm -rf RPi.GPIO-0.*

      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
      GPIO.setmode(GPIO.BOARD)
      
      # 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.setmode(GPIO.BCM)
      GPIO.setup(17, GPIO.IN)
      GPIO.setup(18, GPIO.OUT)
      input_value = GPIO.input(17)
      GPIO.output(18, GPIO.HIGH)
      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleSend Text and HTML Email Using Python on the Raspberry Pi
      Next Article Enable SSH (Secure Shell) on the Raspberry Pi

      Related Posts

      Disable SSH Password Login on Raspberry Pi

      How to Add a Raspberry Pi Pico Reset Button

      Pi Pico Onboard LED

      17 Comments

      1. oluwatoyi on July 3, 2014 12:00 pm

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

        Reply
        • Matt on July 3, 2014 12:16 pm

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

          Reply
      2. Ganesh on August 21, 2014 5:01 am

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

        Thanks in advance!!

        Reply
        • Matt on August 21, 2014 10:07 am

          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.

          Reply
      3. Robert @ Recupero Dati Server on January 8, 2015 5:22 pm

        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
        Roberto

        Reply
        • Matt on January 8, 2015 7:10 pm

          If you use the latest version of Raspbian you don’t need to install manually.

          Reply
      4. Frank Carraro on February 24, 2015 9:06 pm

        When I run my script with the GPIO commands, the SETUP command returns a runtime error with “no access to /dev/mem” The import and setmode commands precede the setup command OK. What am I missing?

        Reply
      5. tanuha on March 21, 2015 5:38 pm

        How do i get to see all GPIO python commands and syntaxes?

        Reply
        • Matt on March 24, 2015 10:14 am

          The examples here cover most of the commands : http://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/

          Reply
      6. Matt on February 17, 2016 1:19 pm

        If you use the latest version of Raspbian you don’t need to install separately.

        Reply
      7. walter on March 6, 2016 6:00 am

        i follow your instruction but
        when i run my script i’ll get this
        sudo python LED.py
        Traceback (most recent call last):
        File “LED.py”, line 4, in
        GPIO.setmode(GPIO.BCM)
        AttributeError: ‘module’ object has no attribute ‘setmode’

        Reply
        • Matt on March 19, 2016 11:54 am

          Are you using the latest Raspbian image? It looks like RPi.GPIO isn’t installed properly. On the latest image RPi.GPIO is already included and doesn’t need installing separately.

          Reply
      8. . on June 16, 2018 3:29 pm

        Packages on PyPi are installable with pip, and you should only need to download their archives if your device has no internet and/or pip.

        For Python 2:
        # pip install RPi.GPIO

        For Python 3:
        # pip3 install RPi.GPIO

        Reply
      9. Alex on March 26, 2019 8:21 am

        Awesome dude, i’m new on this world and your post really help me.

        Reply
      10. ameer on April 14, 2019 4:08 am

        thank you

        Reply
      11. jeran on January 3, 2020 5:03 pm

        hi, i am using the Raspberry pi desktop and rpi.gpio is already installed in it but the python keeps throwing error of no found RPi.GPIO module, i dont have raspberry pi board so just wanted to code and practice with interpreter, please help.

        Reply
        • Matt on January 4, 2020 12:31 pm

          Because there are no physical GPIO pins when using Raspbian on a PC/laptop you can’t use the GPIO library. It is possible to connect a Pi Zero to act as a “GPIO expander” so you can write code on a PC. More details here : https://www.raspberrypi.org/blog/gpio-expander/

          Reply
      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      February 16, 2024

      Disable SSH Password Login on Raspberry Pi

      March 13, 2023

      Elecrow Meteor IPS Touchscreen with RGB LEDs

      December 26, 2022

      Pi Pico Pinout Display on the Command Line

      December 23, 2022

      How to Add a Raspberry Pi Pico Reset Button

      November 20, 2022

      Pi Pico Onboard LED

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Pico
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter Kodi LCD LED Linux media Minecraft Model A motionEyeOS PCB photography photos Pi-Lite Pi Pico power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI SSH temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2025 - All Rights Reserved - Matt Hawkins

      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Latest Posts
      February 16, 2024

      Disable SSH Password Login on Raspberry Pi

      March 13, 2023

      Elecrow Meteor IPS Touchscreen with RGB LEDs

      December 26, 2022

      Pi Pico Pinout Display on the Command Line

      Mastodon YouTube Instagram Facebook Pinterest RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2025 - All Rights Reserved - Matt Hawkins

      mastodon.social@RPiSpy

      Type above and press Enter to search. Press Esc to cancel.