简体   繁体   English

Python 3.9.7 脚本无法在 ubuntu crontab 上运行

[英]Python 3.9.7 script failing to run on ubuntu crontab

I am currently attempting to setup a raspberry pi 4 as an intercom system using ubuntu 21.10.我目前正在尝试使用 ubuntu 21.10 将树莓派 4 设置为对讲系统。 I am using functioning python scripts to play mp3s via cron jobs.我正在使用运行正常的 python 脚本通过 cron 作业播放 mp3。

My scripts are almost exactly the same as this except for differing mp3 files:除了不同的 mp3 文件外,我的脚本几乎与此完全相同:

#!/usr/bin/env python3

from pygame import mixer
from pygame import time
mixer.init(frequency=90000, size=-16, channels=2, buffer=512)
mixer.music.load("/home/intercompi/Music/0min-closing.mp3")
mixer.music.set_volume(0.7)
mixer.music.play()

while mixer.music.get_busy():
    time.Clock().tick(10)
quit()

My crontab is as follows:我的crontab如下:

30 20 * * 1-4 /home/intercompi/30min-closing.py >> IntercomOutput.txt 2>&1
45 20 * * 1-4 /home/intercompi/15min-closing.py >> IntercomOutput.txt 2>&1
55 20 * * 1-4 /home/intercompi/5min-closing.py >> IntercomOutput.txt 2>&1
0 21 * * 1-4 /home/intercompi/0min-closing.py >> IntercomOutput.txt 2>&1
30 17 * * 0,5,6 /home/intercompi/30min-closing.py >> IntercomOutput.txt 2>&1
45 17 * * 0,5,6 /home/intercompi/15min-closing.py >> IntercomOutput.txt 2>&1
55 17 * * 0,5,6 /home/intercompi/5min-closing.py >> IntercomOutput.txt 2>&1
0 18 * * 0,5,6 /home/intercompi/0min-closing.py >> IntercomOutput.txt 2>&1

and my logging file outputs this:我的日志文件输出这个:

/bin/sh: 1: usr/bin/python3: not found
/bin/sh: 1: usr/bin/python3: not found
/bin/sh: 1: usr/bin/python3: not found

I am fairly inexperienced with linux so I apologize if this is sloppy.我对 linux 相当缺乏经验,所以如果这很草率,我深表歉意。 This is partly a consolidation of my previous attempts at looking into this issue.这在一定程度上是对我之前研究这个问题的尝试的整合。

Does "/usr/bin/env python3" on command line navigates you to python console?命令行上的“/usr/bin/env python3”是否将您导航到 python 控制台?

you can also use the output of the "which" command in your script.您还可以在脚本中使用“which”命令的 output。

which python3

for instance例如

#!/usr/bin/python3

from pygame import mixer
from pygame import time
mixer.init(frequency=90000, size=-16, channels=2, buffer=512)
mixer.music.load("/home/intercompi/Music/0min-closing.mp3")
mixer.music.set_volume(0.7)
mixer.music.play()

while mixer.music.get_busy():
    time.Clock().tick(10)
quit()

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

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