-1

I have a python file which executes perfectly in shell environment, however when I try to implement it from the crontab, it doesn't execute at all..

The following code is what I run in the crontab:

* * * * * /usr/bin/python3 /home/maestro/Desktop/Check_monitors.py >> /home/maestro/Desktop/text.txt 2>&1

I am 99% percent sure the code in crontab is correct. I have also checked which python version is being used in the shell and it is 3.6, located at /usr/bin/python3.

The error message printed out from the cron job is as follows:

Traceback (most recent call last):
  File "/home/maestro/Desktop/Check_monitors.py", line 7, in <module>
    import pandas
  File "/usr/local/lib/python3.6/dist-packages/pandas/__init__.py", line 17, in <module>
    "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
dateutil: No module named 'dateutil' ```

Obviously I tried the default to install the module as follows:

pip3 install python-dateutil Resulting in:Requirement already satisfied: python-dateutil in ./.local/lib/python3.6/site-packages Requirement already satisfied: six>=1.5 in ./.local/lib/python3.6/site-packages (from python-dateutil)

Which does seem logical as I am able to run it from the shell. It must have something to do with dateutils within cron but I am not able to figure out how to solve it.

I did find some more information on the error here: https://bugs.launchpad.net/python-crontab/+bug/1167180 but am not sure how this could lead to a solution. All help would be appreciated.

Rivered
  • 741
  • 7
  • 27
  • Try running your code as `root` user, not as cron job – ofirule Mar 19 '20 at 23:52
  • The whole idea is that it executes via cron as to have it executed an x amount of times a day, as normal or root user I can run the code but that is not the purpose. – Rivered Mar 23 '20 at 12:22
  • The idea was that you will try to run the code as `root` user and if it doesn't work then solve that first, and if it does work then try to understand what's the difference between running the cron job and running the code as root user. Because there is clearly a difference in the environment the way you run your code now and the way it's running via the cron job – ofirule Mar 23 '20 at 16:06

1 Answers1

0

Apparently the following solved my problem:

sudo apt-get install python3-dateutil
Rivered
  • 741
  • 7
  • 27