我正在尝试通过 EC2 上的 crontab 运行 Python 脚本(它是网络抓取)。但它不起作用。
这是我的任务:
SHELL = /bin/bash
PATH = /usr/local/sbin:/usr/local / bin: / sbin: / bin: / usr / sbin: / usr / bin
* * / 2 * * * / usr / bin / python /home/ec2-user/LATAM_v1.py
我收到来自系统的电子邮件,说未安装 pandas。
但它已安装。
我还直接在 shell 中运行脚本:
/home/ec2-user/LATAM_v1.py
/ usr / bin / python home / ec2-user / LATAM_v1.py
两种方法都奏效了。
如果它们正在运行,我已经检查了 cron 和守护程序的状态,它们是。
这是错误:
From [email protected] Sun Apr 12 10:10:02 2020
Return-Path: <[email protected]>
Received: from ip-172-31-3-2.sa-east-1.compute.internal (localhost [127.0.0.1])
by ip-172-31-3-2.sa-east-1.compute.internal (8.14.4/8.14.4) with ESMTP id 03CDA2Lb008039
for <[email protected]>; Sun, 12 Apr 2020 10:10:02 -0300
Received: (from root@localhost)
by ip-172-31-3-2.sa-east-1.compute.internal (8.14.4/8.14.4/Submit) id 03CDA2W8008038;
Sun, 12 Apr 2020 10:10:02 -0300
Date: Sun, 12 Apr 2020 10:10:02 -0300
Message-Id: <202004121310.03CDA2W8008038@ip-172-31-3-2.sa-east-1.compute.internal>
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <root@ip-172-31-3-2> /usr/bin/python /home/ec2-user/LATAM_v1.py
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Traceback (most recent call last):
File "/home/ec2-user/LATAM_v1.py", line 10, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
This is the version of the machine:
NAME = "Amazon Linux AMI"
VERSION = "2018.03"
ID = "amzn"
ID_LIKE = "rhel fedora"
PRETTY_NAME = "Amazon Linux AMI 2018.03"
我已经审查了 Stackoverflow,我得到了很多答案等等,但这里没有任何效果。
我对Linux不熟悉。如果有人知道如何解决它并逐步解释它,我将不胜感激。
非常感谢。