[英]crontab in mac is not working properly for python script
crontab -l:
(base) yan@0053 notebooks % crontab -l
* * * * * /opt/anaconda3/bin/python /Users/yan/Documents/pol/coop/analysis/test.py
* * * * * echo "hello" >>/Users/yan/Documents/pol/coop/analysis/hello.txt
Does NOT work in crobtab:
* * * * * /opt/anaconda3/bin/python /Users/yan/Documents/pol/coop/analysis/test.py
Does work in crontab:
* * * * * echo "hello" >>/Users/yan/Documents/pol/coop/analysis/hello.txt
BUT this python script works in Terminal, and i have the output file saved in the folder:
(base) yan@0053 notebooks % /opt/anaconda3/bin/python /Users/yan/Documents/pol/coop/analysis/test.py
我想知道如何在 crontab 中调试 python.py。 我无法在终端中手动运行它...
我的test.py:
import pandas as pd
df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
'mask': ['red', 'purple'],
'weapon': ['sai', 'bo staff']})
df.to_csv('ouoput.csv', index=False)
基本上,不应该是 test.py 问题,因为我只是修改了 test.py 并且只包含一行 print('y')。 它可以手动工作,但不能在 crontab 中工作
print('y')
在 MacOS 上,CronTab 自 10.4 起已被弃用。 不支持。 我建议从 Crontab 转移到 launchd。 简而言之,您可以根据说明创建 .plist 文件。 有一个名为 LaunchControl 的优秀小应用程序,它对运行后台系统脚本和进程非常有帮助。 强烈推荐,因为语法和权限/安全设置可能很棘手。 此外,还有这篇很棒的小文章“如何使用 launchd 在 macOS 中运行服务”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.