简体   繁体   中英

Automatically running python script on raspberry pi

I am trying to run my python script automatically when the system reboots. I have followed a bunch of other threads about this topic and think i am close, but getting a permission denied error.

My script uses GPIO and Tkinter and is written in Python 3.2.3

The first step was i added this line to the top of my script.

#! /usr/bin python3.2

I saw other posts where they did /bin/etc python from what i can tell python is not installed here and throws other errors if i try to do that. I also tried just python instead of python 3.2 but i think i should have 3.2

I then went to the terminal and ran this command.

sudo chmod +x /home/pi/FDRT/stopclock.py

this returned immediately with out any errors.

I then modified LXDE autostart file

sudo nano ~/etc/xdg/lxsession/LXDE/autostart

I added this line to the bottom.

/usr/bin/sudo ~/FDRT/stopclock.py

I then rebooted the pi and it didn't do anything in /home/pi I opened .xsession-errors file and see i have a permission denied error.

I then just tried to run the same command in the terminal window

/usr/bin/sudo ~/FDRT/stopclock.py

this returns the same permission denied error.

Could someone help me on what I am doing wrong here?

The fact that you're getting permission denied locally should make this easier to debug. The first issue is that you appear to be missing a / Change:

> #! /usr/bin python3.2

to

> #!/usr/bin/python3.2

Edit to respond to Joran's comment:

Note that if you have the following simple program (set to permission 755)

#! /usr/bin python
print "Hello world"

Running it as python test.py will print out hello world; running it as ./test.py returns: -bash: ./test.py: /usr/bin: bad interpreter: Permission denied (at least on my system; I thought I've seen just Permission denied elsewhere), which is why I was hoping this would resolve the issue without further tests (assuming that is how the OP had the shebang and wasn't just an artifact of pasting into SO)

Also, I'd suggest replacing the ~ with the real path (/home/pi) in your steps just to make sure somewhere something isn't expanding it to eg root's home (assuming /home/pi isn't root's home on a RPi)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM