问题是,当脚本通过 cron 运行时,由于某种原因找不到模块,但如果直接通过 Python 运行它,那么一切都很好
克朗:
*/5 * * * * python /home/shhegolev/scripts/code5M_simple.py >> /home/shhegolev/scripts/logs.log 2>> /home/shhegolev/scripts/errors.log
cat errors.log
输出:
Traceback (most recent call last):
File "/home/shhegolev/scripts/code5M_simple.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
但如果我直接这样做:
~/scripts$ python code5M_simple.py
或从 cron 复制命令:
~/scripts$ python /home/shhegolev/scripts/code5M_simple.py >> /home/shhegolev/scripts/logs.log 2>> /home/shhegolev/scripts/errors.log
一切都好!
pip install numpy
说:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in /home/shhegolev/.local/lib/python3.7/site-packages (1.21.5)
我不知道出了什么问题
代码:
head -10 code5M_simple.py
import numpy
import talib
import csv
import time
from numpy import genfromtxt
import smtplib
import requests
from binance import Client
import random
import datetime