using a library from https://github.com/BLavery/LIBtft144

this line of code doesn't seem to run when I run the program from a systemd. I also tried calling it from a crontab call of my .py program.

TFT.draw_bmp('Astro_helmet.bmp', 1, 1)

however, when I run this program from the commandline, it runs fine! All the line of code does is blit an image to an lcd screen. All I can think of is the image file isn't available when the pi is booting up. Thanks!

Description=My Script Service

ExecStart=/usr/bin/python3 /home/pi/Py/scripts/LIBtft144/ipPrint.py


I'm using Python3.5

  • There is no display associated with a cron job (or systemd by the sound of it). – joan Dec 3 '18 at 14:32
  • Joan, I used the crontab to call a python program which operated a display – Russell Moore Dec 3 '18 at 21:39

I realized that I did not put the path to the file. that's why it would run from commandline when in that directory, but not from any directory.

  • You added this as an answer. Does that mean your problem is solved? – Dirk Dec 3 '18 at 15:42
  • As far as I see in your question any file is addressed with full path. So what file do you mean, you don't addressed with full path? Please address me with @Ingo, otherwise I won't see your reply. – Ingo Dec 3 '18 at 17:04

It seems you've figured how to fix your issue, but perhaps not why the fix is needed? If that's the case, consider this:

  1. When you run a program from the command line, it runs in the environment (env) of the user (pi?) that invoked the program. That environment includes permissions, and a PATH (discoverable via echo $PATH). When you run a program from cron, or systemd, the program will NOT, in general, run in the same environment. As you've learned, the way to work around this is to use full path specs for all files and programs needed in your script.

  2. You are also correct in that scripts run under cron may fail unexpectedly (esp. when using the @reboot invocation) because cron maintains no awareness of whether or not the resources required to execute a command are available before attempting the execution. Redirecting stderr to a log file in your cron command may give you some insights on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.