I'm trying to test the following simple "blink" RPi.GPIO Python script.

import RPi.GPIO as GPIO

LED_PIN = 18 # GPIO 18, (P1 pin 12)

print 'A'
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
print 'B'
GPIO.setup(LED_PIN, GPIO.OUT) # LED pin output
print 'C'
GPIO.output(LED_PIN, GPIO.LOW) # LED off

while 1:
    print 'D'

    print 'E'
    GPIO.output(LED_PIN, GPIO.LOW)        

When I run this, I get the output:


then the program appears to exit when it tries to call GPIO.setup(...), but no error or segfault is shown. Since there's no error message, I'm quite bewildered and not quite sure where to go from here.

What's wrong with my script? What would be causing GPIO.setup() to fail?

I'm running Ubuntu 14.04. Please don't recommend that I use Raspbian.

  • I'm sure you might have done this, but did you try running your script with sudo ? Commented Oct 18, 2015 at 5:12

1 Answer 1


It is a known issue with the RPi.GPIO module on Ubuntu.


I am not aware of a workaround.

I think a likely reason is some of the system files being in a different place on Ubuntu.

You could try my pigpio Python module. It may work.

  • You're right, the problem is inherent in the design of RPi.GPIO, which writes directly to /dev/mem. This is generally bad practice. Raspbian's kernel has been specially compiled to allow this, but most kernels are configured to prevent this access. The solution to my problem was to abandon RPi.GPIO and use a better library like WiringPi2 which accesses the GPIO pins via the /sys/class/gpio files.
    – Cerin
    Commented Oct 18, 2015 at 13:52
  • All the GPIO libraries use /dev/mem as to be useful they need to manipulate aspects of the GPIO which are not exposed by the sysfs interface. wiringPi/wiringPi2 does use /dev/mem (or possibly /dev/gpiomem now, but it's pretty unlikely that /dev/gpiomem exists in Ubuntu).
    – joan
    Commented Oct 18, 2015 at 14:51
  • If wiringPi uses /dev/mem, it's not doing so for any features I'm need. I'm running as non-root, and if it tried to use /dev/mem, it would die just like my RPi.GPIO script did.
    – Cerin
    Commented Oct 18, 2015 at 17:39
  • @Cerin It certainly uses /dev/mem or /dev/gpiomem. It is handled in the wiringPiSetup code in wiringPi.c. I think the code is called up unless you use the wiringPiSetupSys method which assumes you have previously set up all the GPIO you want via the sysfs interface.
    – joan
    Commented Oct 18, 2015 at 18:17

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.