2

Main problem is that when I want to run Python (.py) programs, I get error saying I need to run from the "root". I thought this meant I needed to have my python program in the folder "root". In the Python shell, I am denied access to the "root" folder.

BackGround : New to the Raspberry Pi. I received a new RPi, along with noobie software. I intend to use Python to do most programming. I allowed Raspian and Python to install. During setup I told system to Not boot into GUI (just to be safe).

My program (test.py) will run from the Linux prompt (Outside of the GUI). At bootup, I change the directory to where my file is (cd Marla_Folder). I then type "sudo python test.py". I don't yet know why I need "sudo", but from researching, I discovered that this works.

I now want to work within in the GUI since I can see that the GUI will be easier to work within.

I start the GUI using "startx" and all is well.

Using LXTerminal in my directory, all works well if I type "sudo python test.py. Program runs.

When I use the "IDLE" or "IDLE3" (Python Shell), I open my file (test.py). Another window opens and I can see my program. I then use pull down menu RUN. And I select "RUN MODULE". I get error : Run time error . . . import RPI.GPIO as RPIO . . . no access to /dev/mem" and message saying "Try running as Root"

It seems to me that I have my file in a folder that can't be run from the "root" By the way, I am familiar with old DOS (but not Linux), thus my feeling I have a wrong folder.

QUESTION : I want to use the "Idle" and "Idle3" (Python shells ). I like the way commands are colored to make recognition better. I get error and message telling me to "try running from the root. How can I run from the root when using Idle and Idle3 ? I have tried searching the site here with lots of keywords, and have been unsucsessful.

2

As answered earlier the problem is with needing root privileges to access /dev/mem. Programs which manipulate the gpios need to use /dev/mem as the gpios are memory mapped. The RPi and RPIO Python packages access /dev/mem and require root privileges to run.

The pigpio Python module works differently. It does not require you to use root privileges to run Python. It communicates with a separate daemon process which may be loaded at system start-up. The daemon alone needs to be run with /dev/mem privileges.

  • thank you for the link to pigpio. Question : After login (at the Linux prompt, can I simply type "sudo pigpio" to install? I don't want to make a non-reversable error (still stumbling with Linux understanding. – Marla May 12 '14 at 14:24
  • Once the library has been built and installed (make/make install) the daemon can be started by sudo pigpiod. The daemon will then remain in memory until killed (sudo killall pigpiod) or the system is rebooted. – joan May 12 '14 at 14:28
2

Obvious (but wrong on so many levels) solution would be run IDLE as root using sudo command. this might work, but it's very dangerous from the security standpoint.

A better solution would be to open your python files in IDLE to edit, and open another terminal window on the desktop, where you may type sudo python yourscripy.py and have it run with escalated privileges.

You don't need access to /root folder to do anything from above, folder /root is not supposed to be used for everyday purpose.

  • thank you lenik. I have been opening another terminal and running the files. That was how I had verified that my code worked. I guess I was just being typical lazy when I saw the one click "RUN MODULE" button in IDLE. All comments and Answers have helped me to move forward. – Marla May 12 '14 at 14:19
  • glad to help =) – lenik May 12 '14 at 14:42
1

Unless you post your Python program there is no way of determining exactly what your problem is.

I assume you are trying to access the GPIO via the /dev memory mapping, and for this you need root permission (this is what sudo does at the terminal).

There are many ways around this e.g. setting suid permission on the memory mapped devices or using the WiringPi http://wiringpi.com/ gpio utility.

  • his/her problem is accessing /dev/mem through GPIO package without enough privileges as the error message clearly says, why do you need any source code to figure this out? – lenik May 12 '14 at 6:13
  • @lenik I guessed this - as you would see from my reply. This does not however enable you to make any constructive suggestions to help the questioner. – Milliways May 12 '14 at 7:11

protected by Community Sep 20 '15 at 11:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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