Page 1 of 1

No access to DEV/MEM

Posted: Wed Dec 03, 2014 4:25 pm
by Roddus
When I write a program in Python using IDLE3, I can run it from the IDLE3 Python shell. But when I add GPIO.setup(7, GPIO.out) to my code I get an error message 'No access to DEV/MEM Try running as root.
To make it run, I have to go to the terminal and type SUDO python filename.py then it works.
The identical code on my friend's Raspberry Pi runs perfectly from within the IDLE3 Python shell. I have spent hours trying to get to the bottom of this problem and got nowhere, please can someone help me?

Re: No access to DEV/MEM

Posted: Wed Dec 03, 2014 5:04 pm
by joan
The actual message you saw should have been dev/mem and the command you used should have been sudo. It doesn't matter here but it can help us to help you if you give accurate error messages.

I guess your friend is running as root, perhaps by using the command sudo idle3

Re: No access to DEV/MEM

Posted: Wed Dec 03, 2014 8:12 pm
by jamesh
In order to access GPIO's you must run as root as Linux will not let you play around with the hardware without the right privileges. So you are right that you need sudo, but i suspect your friend is also running as root somehow (see previous post)

Re: No access to DEV/MEM

Posted: Wed Dec 03, 2014 8:49 pm
by Roddus
Thank you for such a prompt and correct answer, and I will try and be more precise with error messages etc. in the future.
Yes, my friend was indeed invoking IDLE3 by typing sudo IDLE3 at the terminal, whilst I was invoking it from the GUI desktop.
So this (my first!) post is now closed - thanks again

Re: No access to DEV/MEM

Posted: Sat Dec 12, 2015 9:59 pm
by pcopa
I'm new to RPI 2 and have simmelar question.
I've setup my RPI with VCN as described in my living room and was able to open, edit and run existing ,py scripts from my desktop using VCN.
Then I moved the RPI to the basement where the sensors are and created my first scrip. Everything's fine till I hit the first GPIO command and get the "No access to /dev/mem" error.

When trying the "sudo idle3" in the LXTerminal, I get the error blow.

Where did I go wrong?

Re: No access to DEV/MEM

Posted: Sun Dec 13, 2015 12:34 am
by DougieLawson
Try running idle with gksudo idle.
Or rewrite your python program to use GPIOzero (which doesn't need sudo or gksudo).

Re: No access to DEV/MEM

Posted: Mon Dec 14, 2015 5:00 pm
by pcopa
DougieLawson wrote:Try running idle with gksudo idle.
:D Hallelujah :D This works. Thanks DougieLawson.

Re: No access to DEV/MEM

Posted: Tue Dec 15, 2015 5:47 pm
by pcopa
Or rewrite your python program to use GPIOzero (which doesn't need sudo or gksudo).
Tried to install gpiozero with both sudo and gksudo without sucsess. see below
(spidev had the same issue)

Or is there another way to rewrite python? (trough VNC)

Re: No access to DEV/MEM

Posted: Wed Dec 16, 2015 9:24 am
by DougieLawson
What OS are you running Jessie or Wheezy?

Have you run sudo apt-get update && sudo apt-get upgrade recently? If not do that and try again with sudo apt-get install python-gpiozero python3-gpiozero

Re: No access to DEV/MEM

Posted: Sat Jan 02, 2016 4:35 pm
by ben_nuttall
The new Jessie image contains the fix to make GPIO work without sudo, and also comes with GPIO Zero pre-installed.

Grab it from the downloads page