[英]crontab not running python script for Rpi.GPIO
我有一個python腳本,我正在嘗試使用以下命令在啟動時運行
sudo crontab -e
使用以下命令
@reboot python /usr/local/sbin/ShutdownJumper.py
腳本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")
重新啟動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
嘗試在crontab上使用此代碼
@reboot cd /usr/local/sbin && sudo python ShutdownJumper.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.