通过crontab运行python脚本找不到导入 [英] Running python script through crontab can't find imports

查看:421
本文介绍了通过crontab运行python脚本找不到导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过crontab运行python脚本,但是以这种方式运行时,它无法导入所需的任何库。当我在crontab之外运行脚本时,没有问题,并且我知道我已经安装了这些库。

I'm trying to run a python script through crontab, but it can't import any of the libraries that it needs when it is run this way. When I run the scripts outside of crontab, there is no issue, and I know that I have these libraries installed.

我是否需要指定它们的路径或其他内容?

Do I need to specify a path to them or something?

非常感谢

crontab文件:

crontab file:

SHELL=/bin/bash
MAILTO=jess.chambers@gmail.com
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G1 -S0 >>/tmp/stdout.log 2>&1
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G2 -S20 >>/tmp/stdout.log 2>&1
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G3 -S40  >>/tmp/stdout.log 2>&1

错误日志:

Traceback (most recent call last):
  File "newRdvChecker.py", line 2, in <module>
    import requests

我正在Linux Mint计算机上运行此设置差异

I'm running this setup on my Linux Mint computer, if that makes a difference

推荐答案

确定从CLI运行脚本时使用的确切python可执行文件(其中哪个python ),然后在crontab中指定python的完整路径。

Determine what exact python executable you use when running the script from CLI (with which python) and specify the full path to python in your crontab.

这篇关于通过crontab运行python脚本找不到导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆