首页 > 解决方案 > Crontab 没有在我的 Mac 上执行 Python 脚本?

问题描述

我可以在我的终端 /Users/quintus/opt/anaconda3/bin/python /Users/quintus/Desktop/python/04_Jobs/Jobs.py 中运行它

但是,我无法设置我的 crontab,我输入 48 23 * * * /Users/quintus/opt/anaconda3/bin/python /Users/quintus/Desktop/python/04_Jobs/Jobs.py

我阅读了类似的问题,但没有找到解决方案。

标签: pythonmacoscronschedule

解决方案


我有一段时间没有在我的 Mac 上工作了,但我只是登录来测试一下。如果您尝试以下操作,它可能会起作用:

48 23 * * * python3 /Users/quintus/Desktop/python/04_Jobs/Jobs.py

这将使脚本在 Python 3.x 中运行,如果您想使用 Python 2.x,只需将 python3 替换为 python。我可能没有做一些额外的事情来让 python3 命令工作,但如果是这样的话,那是很久以前的事了。

此外,这将每 48 小时 23 分钟运行一次。我只想指出这一点,因为这似乎很奇怪。


推荐阅读