0

I wrote a script that I'd like to be started on powerup of the machine. So I added the line

@reboot /usr/bin/env python3.8 /root/scripts/TelegramBotNetflixReminder/netflix_reminder.py >> /root/scripts/netflixReminder.log 2>&1

to crontab via crontab -e. The log file now shows me an error

Traceback (most recent call last):
  File "/root/scripts/TelegramBotNetflixReminder/netflix_reminder.py", line 11, in <module>
    from dateutil import relativedelta
ModuleNotFoundError: No module named 'dateutil'
Traceback (most recent call last):
  File "/root/scripts/TelegramBotNetflixReminder/netflix_reminder.py", line 11, in <module>
    from dateutil import relativedelta
ModuleNotFoundError: No module named 'dateutil'

However when I type /usr/bin/env python3.8 and in the python console import dateutil, everything works.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Python packages are installed on a per-user basis, if the cron user is different than the one that installed dateutil it won't find it. – Jared Smith Aug 29 '20 at 01:28
  • @JaredSmith The crontab line I added is visible at `sudo crontab -e` and I added a line in my script to print out the current user. It is 'root'. So as I execute the script as root and cron does so too, might that not be the problem? – Felix Dobler Aug 29 '20 at 11:03
  • Hnw did you install `dateutil`, where? See also https://stackoverflow.com/questions/22743548/cronjob-not-running which has a number of troubleshooting tips. – tripleee Aug 29 '20 at 11:16
  • @FelixDobler you would have had to *install the dateutil package* as root. I can't necessarily tell you how to do that as it can vary a bit by distro. For ubuntu variants type `sudo su` and then `python3 -m pip install --user dateutil` *should* do the trick. IDK, I've been doing that sort of thing via ansible for so long now that I kinda forget. Note that pip might complain about you doing this, normally you don't install packages as root. – Jared Smith Aug 29 '20 at 11:44
  • 1
    All right so I suppose the problem came from pyenv where the library was installed. Can't say that for sure though as I broke my system while trying to remove the pyenv environmental variables. With a fresh installation of Ubuntu and after adding the module with `python3 -pip install python-dateutil` it works now. So not quite sure what the problem was here. Thanks for your help anyways – Felix Dobler Aug 29 '20 at 15:41
  • @felixdobler no problem, glad you got it resolved – Jared Smith Aug 29 '20 at 18:26

0 Answers0