PiPi666
Posts: 2
Joined: Sat Dec 06, 2014 3:37 am

RuntimeError: No access to /dev/mem. Try running as root!

Sat Dec 06, 2014 4:34 am

Hi everyone,

I just tried runing the examples in PYTHON PICAMERA SETUP. The code of CAMERA PROGRAMMING: CAPTURE AN IMAGE worked well but I encountered a problem in the next example: CAMERA PROGRAMMING: CAPTURE WHEN ACTIVATED. The error message is as below:

Traceback (most recent call last):
File "/home/pi/my.py", line 6, in <module>
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) # new
RuntimeError: No access to /dev/mem. Try running as root!

I just copied the example code and believe there should be no code error.

anyone's help will be highly appreciated!

Code: Select all

import time
import picamera
import RPi.GPIO as GPIO  # new

GPIO.setmode(GPIO.BCM)  # new
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP)  # new

with picamera.PiCamera() as camera:
    camera.start_preview()
    GPIO.wait_for_edge(17, GPIO.FALLING)  # new
    camera.capture('/home/pi/Desktop/image.jpg')
    camera.stop_preview()

User avatar
rpdom
Posts: 17173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: RuntimeError: No access to /dev/mem. Try running as roo

Sat Dec 06, 2014 7:13 am

GPIO accesses need to have root level access. Ordinary users aren't allowed to access them.

To run your program as root from the command line put "sudo " in front of the command.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: RuntimeError: No access to /dev/mem. Try running as roo

Sat Dec 06, 2014 8:12 am

If you are following http://www.raspberrypi.org/learning/pyt ... era-setup/, the instructions are correct.

Under "Camera programming: capture an image" Step 2 requires you to start IDLE (the python editing environment) with sudo idle &

Doing that will resolve your problem.

PiPi666
Posts: 2
Joined: Sat Dec 06, 2014 3:37 am

Re: RuntimeError: No access to /dev/mem. Try running as roo

Sat Dec 06, 2014 4:05 pm

Thank you so much. The problem was solved.

Return to “Python”