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

2024-06-16 08:24:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个在mac上调用python脚本的shell脚本。如果我从命令行运行,它运行良好。如果在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

谢谢你对如何修复它的任何建议


Tags: no命令行env脚本binmacusr错误
1条回答
网友
1楼 · 发布于 2024-06-16 08:24:48

在@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.

我将语句PATH=添加到crontab的顶部,它可以正常工作

相关问题 更多 >