Python Forum
ModuleNotFoundError only if script is launched by cron
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ModuleNotFoundError only if script is launched by cron
#3
Yes it does :
pi@raspberrypi:~ $ sudo su
root@raspberrypi:/home/pi# bash lancement.sh
root@raspberrypi:/home/pi# Traceback (most recent call last):
File "/home/pi/domoticz/scripts/snap2.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'

then I try in lancement.sh :
cd /home/pi/domoticz/scripts
/usr/bin/python3 snap2.py&

and it gives back the same error

then in lancement.sh :
cd /home/pi/domoticz/scripts
/usr/bin/python snap2.py&

and same again.

cv2 is there :
pi@raspberrypi:~/.local/lib/python3.9/site-packages $ ls
cv2 opencv_python-4.5.4.60.dist-info
keyboard __pycache__
keyboard-0.13.5.dist-info python_vlc-3.0.12118.dist-info
numpy vlc.py
numpy-1.21.5.dist-info

and PATH looks correct :
pi@raspberrypi:~ $ echo $PATH
/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/.local/lib/python3.9/site-packages

So what should I change ?
Reply


Messages In This Thread
RE: ModuleNotFoundError only if script is launched by cron - by Charles33 - Feb-03-2022, 06:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 1,011 Nov-16-2022, 07:58 PM
Last Post: Winfried
  script with imports works but pytest gives "ModuleNotFoundError"? Hpao 0 1,629 Jun-27-2021, 08:30 PM
Last Post: Hpao
  Python Script Spawned by Cron or Systemd doesn't write files..? johnnyrobot 2 2,667 May-24-2019, 07:04 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020