Issue
I have an scheduled crontab to run every minute that calls a shell script that runs the python script. My problem is that I get an ModuleNotFoundError. I'm a newbie in terms of cronjobs and Linux
crontab
* * * * * sh /home/pablo_racana/queries/test.sh >> out.txt 2>&1
sh
#!/bin/sh
cd "$(dirname "$0")";
CWD="$(pwd)"
echo $CWD
PYTHONPATH=/home/pablo_racana/.local/lib/python3.7/site-packages/
HOME=/home/pablo_racana
python3 test_cron.py
python script
import datetime
import sys
import pyodbc
import json
import struct
import adal
import time
import pandas as pd
import numpy as np
import os
For each iteration I receive the following error
Traceback (most recent call last):
File "test_cron.py", line 6, in <module>
import adal
ModuleNotFoundError: No module named 'adal'
I saw in a different answer that I needed to add the PYTHONPATH to where my package is installed, but in my case, I have packages instaled in different folders
import pyodbc
print(pyodbc)
/home/pablo_racana/.local/lib/python3.7/site-packages/
import adal
print(adal)
/opt/conda/lib/python3.7/site-packages/
Solution
solved.
I added the following script with the filepaths
import sys
sys.path.append(r'/home/pablo_racana/.local/lib/python3.7/site-packages/')
sys.path.append(r'/opt/conda/lib/python3.7/site-packages/')
Answered By - Racana Answer Checked By - Timothy Miller (WPSolving Admin)