Roddus
Posts: 2
Joined: Wed Dec 03, 2014 4:11 pm

No access to DEV/MEM

Wed Dec 03, 2014 4:25 pm

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?

User avatar
joan
Posts: 15092
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: No access to DEV/MEM

Wed Dec 03, 2014 5:04 pm

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 27417
Joined: Sat Jul 30, 2011 7:41 pm

Re: No access to DEV/MEM

Wed Dec 03, 2014 8:12 pm

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)
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Roddus
Posts: 2
Joined: Wed Dec 03, 2014 4:11 pm

Re: No access to DEV/MEM

Wed Dec 03, 2014 8:49 pm

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

pcopa
Posts: 7
Joined: Tue Dec 08, 2015 10:02 pm

Re: No access to DEV/MEM

Sat Dec 12, 2015 9:59 pm

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?
Attachments
rpiVNC1.jpg
rpiVNC1.jpg (26.93 KiB) Viewed 2318 times

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: No access to DEV/MEM

Sun Dec 13, 2015 12:34 am

Try running idle with gksudo idle.
Or rewrite your python program to use GPIOzero (which doesn't need sudo or gksudo).
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

pcopa
Posts: 7
Joined: Tue Dec 08, 2015 10:02 pm

Re: No access to DEV/MEM

Mon Dec 14, 2015 5:00 pm

DougieLawson wrote:Try running idle with gksudo idle.
:D Hallelujah :D This works. Thanks DougieLawson.

pcopa
Posts: 7
Joined: Tue Dec 08, 2015 10:02 pm

Re: No access to DEV/MEM

Tue Dec 15, 2015 5:47 pm

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)
Attachments
arvix4.jpg
arvix4.jpg (61.69 KiB) Viewed 2144 times

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: No access to DEV/MEM

Wed Dec 16, 2015 9:24 am

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
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
ben_nuttall
Posts: 235
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridgeshire, UK
Contact: Website Twitter

Re: No access to DEV/MEM

Sat Jan 02, 2016 4:35 pm

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
Former RPF staff. Author of gpiozero and creator of piwheels.

Return to “Beginners”