I have a python script I wish to call each day with a cron job. Because the .py script loads several files from it's directory, rather than change all the file paths within the .py script to be full paths, I instead called a .sh script with the cronjob that changes the dir. Here's the .sh script.
#!/bin/bash cd /home/ubuntu/ga_data/gaV4 python gaAPIWorkingVersion.py echo "ran cron at" | tee -a "$tvaUpdater.log" echo $(date) | tee -a "$tvaUpdater.log"
I know that the cronjob ran because I see the right date in the log file. However, the log file contains a message:
Traceback (most recent call last): File "gaAPIWorkingVersion.py", line 13, in from apiclient.discovery import build ImportError: No module named apiclient.discovery
The package is installed. When I call the .sh script directly, outwith cron, everything works as expected.
/home/ubuntu/ga_data/myscript.sh # works
It's only when the script is called from the cron that this error happens.
What could be causing this and is there anything I can add to my crontab or .sh script to successfully run the script?
Note, if it's useful or important, I'm using Anaconda python.