我有一个python脚本,我试图在启动时使用
运行@reboot python /usr/local/sbin/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")
脚本ShutdownJumper.py以:
开头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
当我重启我的RPi时,我收到了以下电子邮件:
echo "hello"
我尝试过更改PATH in the crontab,所以无济于事。
答案 0 :(得分:1)
尝试在crontab上使用此代码
@reboot cd /usr/local/sbin && sudo python ShutdownJumper.py