Feb-03-2022, 05:19 PM
Hello
I want to launch a python program at start of the system, which uses openCV.
unfortunately, I get a ModuleNotFoundError on cv2 ONLY when the script is launched
by cron. Why ?
environment :
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Python version :
pi@raspberrypi:~ $ ls /usr/bin/python*
/usr/bin/python /usr/bin/python3.9 /usr/bin/python3-config
/usr/bin/python3 /usr/bin/python3.9-config
opencv :
pi@raspberrypi:~ $ python3
>>> import cv2
>>> cv2.__version__
'4.5.4'
the automatic launch in Crontab :
@reboot sh /home/pi/lancement.sh > /home/pi/logs/log.txt 2>&1
lancement.sh
cd /home/pi/domoticz/scripts
/usr/bin/env python3.9 snap2.py&
If I launch lancement.sh manually, "import cv2" doesn't cause any error
and the program executes without any problem.
when cron calls lancement.sh, I get the error in log.txt :
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/snap2.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
Thank you for your help.
I want to launch a python program at start of the system, which uses openCV.
unfortunately, I get a ModuleNotFoundError on cv2 ONLY when the script is launched
by cron. Why ?
environment :
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Python version :
pi@raspberrypi:~ $ ls /usr/bin/python*
/usr/bin/python /usr/bin/python3.9 /usr/bin/python3-config
/usr/bin/python3 /usr/bin/python3.9-config
opencv :
pi@raspberrypi:~ $ python3
>>> import cv2
>>> cv2.__version__
'4.5.4'
the automatic launch in Crontab :
@reboot sh /home/pi/lancement.sh > /home/pi/logs/log.txt 2>&1
lancement.sh
cd /home/pi/domoticz/scripts
/usr/bin/env python3.9 snap2.py&
If I launch lancement.sh manually, "import cv2" doesn't cause any error
and the program executes without any problem.
when cron calls lancement.sh, I get the error in log.txt :
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/snap2.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
Thank you for your help.