Issue
I have a python-script that uses matplotlib and pandas to load and plot some data. The python-script is not worth mentioning.
If a usual user (eg pi
) starts this script, it does well. But soon as cron
starts the same script, libraries such as pandas can not be loaded any more.
To gain some more information I wrapped the python-script in a bash-script. I have checked env
(including PATH
) and they seem to be the same for cron
and pi
. As long as usual user pi
starts the script, it looks well:
Start plot_mean_error_by_hour.bash
SHELL=/bin/bash
LANGUAGE=de_DE.UTF-8
NO_AT_BRIDGE=1
PWD=/home/pi/public_html
LOGNAME=pi
XDG_SESSION_TYPE=tty
HOME=/home/pi
LANG=de_DE.UTF-8
LS_COLORS=rs=0: ... :*.xspf=00;36:
SSH_CONNECTION=192.168.178.20 51164 192.168.178.40 22
XDG_SESSION_CLASS=user
TERM=xterm-256color
USER=pi
DISPLAY=localhost:10.0
SHLVL=2
XDG_SESSION_ID=40005
XDG_RUNTIME_DIR=/run/user/1000
SSH_CLIENT=192.168.178.20 51164 22
LC_ALL=de_DE.UTF-8
PATH=.:/:/usr/bin/python3:/usr/lib/python3/dist-packages:/usr/lib/python3/dist-packages/pandas:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/public_html:/home/pi/public_html/plot_mean_error_by_hour.bash
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
MAIL=/var/mail/pi
SSH_TTY=/dev/pts/0
OLDPWD=/home/pi
TEXTDOMAIN=Linux-PAM
_=/usr/bin/env
got pandas from ['/usr/lib/python3/dist-packages/pandas']
can read /home/pi/public_html/testprovider.hdf
read /home/pi/public_html/testprovider.hdf
...
labeled plot
wrote /home/pi/public_html/testprovider.svg
But when cron
uses the same bash-script python fails loading its libraries:
Start plot_mean_error_by_hour.bash
SHELL=/bin/bash
LANGUAGE=de_DE.UTF-8
PWD=/home/pi
LOGNAME=pi
HOME=/home/pi
LANG=de_DE.UTF-8
SHLVL=1
LC_ALL=de_DE.UTF-8
PATH=.:/:/usr/bin/python3:/usr/lib/python3/dist-packages:/usr/lib/python3/dist-packages/pandas:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/public_html:/home/pi/public_html/plot_mean_error_by_hour.bash
_=/usr/bin/env
Both PATH
- and SHELL
-variables are just the same and I like to get some more information why python launched by cron
fails. How can I get more information?
Thanx for any hint
Solution
Silly me! source just did the trick. Added source /home/pi/.bashrc
to the bash-script and python does load it all as supposed.
Answered By - Christian Answer Checked By - Robin (WPSolving Admin)