Picamera2 Does not work in Crontab

Where did you get the camera module(s)?
From you

t
Model number of the product(s)?
64mp arducam

What hardware/platform were you working on?
RPi

Instructions you have followed. (link/manual/etc.)
manual and then troubleshooting the forum

Problems you were having?

Being able to use Picamera2 in Crontab

The dmesg log from your hardware?

Troubleshooting attempts you’ve made?

calling libcamera-still from a call to the command line

What help do you need?

Hi! I got our 64mp arducam working with a RPI 4, and I can write python code and use picamera2 and take photos and set focus and stuff and that’s working ok when I run the python file from the command line or Thonny or Geany.

but when I try to have the same script run from Crontab it won’t start. When i look at the output it will say something like “cannot find camera”

I ended up doing a workaround where instead of calling picamera2, i ended up doing calls to the cmd line from Python, but found I had to write the call like:

cmd = "/usr/local/bin/libcamera-still -o "+filename

Instead of normally just writing:
cmd = "libcamera-still -o "+filename

I guess crontab uses a different path or something to get to the things like libcamera still, and i got this path from running the command line:

pi@raspberrypi:~ $ which libcamera-still
/usr/local/bin/libcamera-still

is there something i need to do in my python code like with the imports?

from picamera2 import Picamera2

Hi,
Can you access the camera by libcamera command?

1 Like

yes i can, and that’s how i hacked it right now, but it goes slower than when i call picamera2 in python

@hikinghack you could solve this problem? i am also facing the same issue

1 Like

@mullermuttu

I haven’t studied the source code in detail yet.

But I want you to try it on other cameras, preferably imx219, to see if you have the same problem, if you have the same problem, you can report this problem to the relevant warehouse. If this problem doesn’t exist with other cameras then I’ll look into this.

1 Like

Hi yeah i figured out the problem it’s a file path problem i think

Crontab uses a different file path for libraries and commands, so you need to say

cmd = "/usr/local/bin/libcamera-still -o "+filename

Instead of normally just writing:
cmd = "libcamera-still -o "+filename

Learn this from doing
pi@raspberrypi:~ $ which libcamera-still
/usr/local/bin/libcamera-still