Skip to content Skip to sidebar Skip to footer

Getting Crontab On Mac To Run Anaconda Installed Python Script (module Not Found)

I am trying to set up crontab for a script written in python which is intalled via Anaconda. The simple .py runs (it just loads a module for a demo) and can be run in terminal with

Solution 1:

You're setting an env.var, cd'ing to a directory, and calling an interpreter, all from crontab.

Under those circumstances, personally I'd find it more elegant to just create a small wrapper script (here called pyscript) that does all that, and call that script from crontab:

$> cat /home/me/bin/pyscript
#!/bin/bash# a.py needs module pandas in /foo/barexport PYTHONPATH=/foo/bar
cd /Users/Esel/Documents/x/y/z || exit
python a.py

$> chmod ug+rx /home/me/bin/pyscript

$> cat /var/spool/cron/crontabs/me
...
* * * * *  /home/me/bin/pyscript

Solution 2:

With some ideas from a roadowl (thanx) and another SOverflow question (54564187) I think I got it running.

SHELL=/bin/sh
PATH=$PATH/Users/Esel/anaconda3/bin:/Users/Esel/anaconda3/condabin:/Applications/anaconda3/bin:/Applications/anaconda3/bin:/Users/Esel/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
* * * * *  cd /Users/Esel/Documents/x/y/z && python a.py

The path came from

echo$PATH

Post a Comment for "Getting Crontab On Mac To Run Anaconda Installed Python Script (module Not Found)"