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
#7
(Feb-03-2022, 11:06 PM)bowlofred Wrote: The PATH doesn't seem that big a deal, both accounts are running "/usr/bin/python3.9". But the import path is different. The "pi" account has a .local site-packages that root isn't accessing.

I suppose something might be setting PYTHONPATH in your environment, but not in root.

Some options for you:

* Does it need to run as root? Could you put it in the "pi" user's crontab instead?
* Add "/home/pi/.local/lib/python3.9/site-packages" to PYTHONPATH in the root environment

(You could also have root install cv2 separately, but then you'd have two copies and a chance that they're not the same version. Better to keep one copy).

Thank you very much !
I could not succeed in adding PYTHONPATH in root environnment (why... If there is a good howto for that I take it !), but finally I put the crontab in the pi user and it works fine !
Reply


Messages In This Thread
RE: ModuleNotFoundError only if script is launched by cron - by Charles33 - Feb-05-2022, 11:39 AM

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