Python crontab and paths

I have driver scripts and Python libraries that are siblings:

/home/mydir/pythonProjs/ 
  • driver.py

  • lib.py

In driver.py , I have a line:

from lib import method1

On my command line on Linux, the following is successfully executed:

 python /home/mydir/pythonProjs/driver.py 

But when I try the following in crontab:

10 1 * * * export PYTHONPATH=~/mydir/pythonProjs; python /home/mydir/pythonProjs/driver.py

I get an error message:

 ImportError: No module named lib.method1 

I also tried changing the path parameter in my crontab command to the fully qualified path /home/mydir/pythonProjs , omitting the "export", and also trying to write .sh files (with the necessary #! Bin / bash ...)

I have one main question and the following question: main: What is the best way to fix my problem? continued: What is the philosophy behind cron with a different path access than my shell?

Before I went down, they voted too quickly, I mentioned that I read, but was not successful (or correctly disassembled) the following: - Where can I set environment variables that crontab will use? - Problems with crontab with running python - http://pythonadventures.wordpress.com/2012/03/31/calling-a-python-script-from-crontab/

+4
python cron environment-variables crontab
Sep 02 '14 at 23:07
source share
1 answer

Try printing environment variables from a dummy job

 * * * * * env > /tmp/env.output 

as suggested at https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work

Also check what crontab shell uses. You can set the environment variable $SHELL to bash by adding the line

SHELL=/bin/bash

at the beginning of the crontab file.

+7
Sep 03 '14 at 7:10
source share
— -



All Articles