脚本在终端上运行,但不是作为 cron

Script runs on terminal, but not as cron

我有一个 shell 脚本,它在 mac 上调用 python 脚本。如果我从命令行 运行,它 运行 没问题。如果我从 cron 作业中执行相同的操作,我会收到错误 "env: python3: No such file or directory"。 python 脚本中的 shebang 行是 "#!/usr/bin/env python3".

如果我将 shebang 行更改为 #!/usr/local/bin/python3 我得到

import boto3
ModuleNotFoundError: No module named 'boto3'

不知道有没有关系,我用自制软件安装了python。

感谢您提出任何修复建议。

在@GordonDavisson 发表上述评论后,

The default PATH for cron jobs is just /usr/bin:/bin, so if you want to run 
anything outside of those directories you need to either use an explicit path 
to the binary, or set the PATH variable in the crontab file.

我在 crontab 的顶部添加了语句 PATH=,它起作用了。