简体   繁体   English

crontab没有为Rpi.GPIO运行python脚本

[英]crontab not running python script for Rpi.GPIO

I have a python script which I am trying to run at boot using 我有一个python脚本,我正在尝试使用以下命令在启动时运行

sudo crontab -e

using the following command 使用以下命令

@reboot python /usr/local/sbin/ShutdownJumper.py

the script ShutdownJumper.py begins with: 脚本ShutdownJumper.py开头为:

#!/usr/bin/env python
#note crontab for superuser required a new PATH variable as here https://unix.stackexchange.com/questions/43392#answer-43394
import subprocess
try:
 import RPi.GPIO as GPIO
except RuntimeError:
 print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")

when I reboot my RPi I get the following email back: 重新启动RPi时,我会收到以下电子邮件:

Traceback (most recent call last):
  File "/usr/local/sbin/ShutdownJumper.py", line 4, in <module>
    import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO

I've tried changing the PATH in the crontab , so no avail.. 我试过更改crontab中PATH ,所以无济于事。

尝试在crontab上使用此代码

@reboot cd /usr/local/sbin && sudo python ShutdownJumper.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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