raspbian: 获取脚本启动故障排除

raspbian: getting a script to start on launch troubleshooting

所以我试图制作 this python script run on launch. It should remain mostly still, but when the motion sensor is triggered, I want the camera to start recording and the motor to move. Ultimately, this process needs to happen when I'm headless, so having it start automatically on bootup is the easiest way to do this. I've tried using this init.d 文件以自动制作它 运行,但我收到以下错误消息:

Starting mylauncher from: can't read /var/mail/gpiozero from: can't read /var/mail/gpiozero from: can't read /var/mail/picamera /home/pi/Detector.py: 4: /home/pi/Detector.py: import: not found from: can't read /var/mail/time /home/pi/Detector.py: 7: /home/pi/Detector.py: Syntax error: "(" unexpected

我用谷歌搜索了一下,有人建议把 #!/usr/bin/python 作为第一行,但是当我这样做时,我得到

File "/etc/init.d/mylauncher", line 18 case "" in ^ SyntaxError: invalid syntax

如何消除这两个错误并确保脚本 运行 在启动时正常运行?

您是否将 #!/usr/bin/python 添加到 init.d 脚本?他们可能意味着您应该将其添加到 python 脚本中。

#!/usr/bin/python 告诉 shell 对 运行 脚本使用什么,所以在行

# run application you want to start
/home/pi/Detector.py

它将使用python来执行脚本。

好的,我明白了。原来我的 Python 代码在开始代码主体之前缺少 while True:,这使得它 运行 一次而不是多次。除此之外,我还从 init.d shell 文件中删除了一些关键组件,这些组件看起来像是注释,但实际上是关于何时启动和停止它的基本信息。此外,我必须将 #!/usr/bin/python 放在我的 Python 脚本之前,这样 init.d 文件就会知道它正在 python 中读取它。最后,我使用了 python /home/pi/Detector.py 而不是 /home/pi/Detector.py,因为即使我在 python 脚本中使用了 #!/usr/bin/python,它也无法使用后者。最后,没有必要守护 shell 或 python 脚本。