I have an LED connected to pin 11 on the Raspberry Pi header, (also known as BCM/GPIO pin 17, and GPIO0). I have installed the Raspberry Pi Python library according to these instructions.

Attempt 1

I installed RPi.GPIO and used the following code from eLinux. I see an error that 'setmode' is not an attribute of the GPIO library.

sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BOARD)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setmode'

Attempt 2

I used a different tutorial, yet I receive the following error:

    sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setup(17, GPIO.OUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init__.py", line 61, in setup
    id = _GetValidId(pin)
  File "/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init__.py", line 52, in _GetValidId
    raise InvalidPinException

I am able to turn on the LED using the GPIO utility:

gpio write 0 0

I have an earlier revision Raspberry Pi.

cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 697.95
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware    : BCM2708
Revision    : 0003
Serial      : 00000000396bd5ea

Why have I been unsuccessful in turning on an LED from Python?

Additional Resources

1 Answer 1


Discovered the problem:

Some guides online instruct you do download version 0.1.0 of the GPIO library which does not have the setup function. You must use a more recent version of the library.


I have downloaded version 0.5.x and it works correctly.


Download from here https://pypi.python.org/pypi/RPi.GPIO

or Download from here http://code.google.com/p/raspberry-gpio-python/downloads/list

Installation Instructions

Extract the script

tar -zxvf RPi.GPIO-0.5.3a.tar.gz
cd RPi.GPIO-0.5.3a
sudo python setup.py install

Here is a python example program that turns two leds off and on every second. It uses the actual pin names, not the GPIO pin names

from RPi import GPIO
from time import sleep

#Use the physical pin numbers, not the logical names

#Set pin 11 and 12 as outputs
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)

#Keep looping over and over
while True:

        #Turn pin 11 off and 12 on
        GPIO.output(11, False)
        GPIO.output(12, True)

        #Wait for 1 second

        #Turn pin 12 off and 11 on
        GPIO.output(11, True)
        GPIO.output(12, False)

        #Wait for 1 second
  • Could you post a new snippit of code to help others wit the same problem? It would earn an upvote from me.
    – Butters
    Aug 15, 2013 at 3:28
  • @Butters I've added some more details on what I did to get it working.
    – spuder
    Aug 15, 2013 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.