1

So I'm having this weird issue.

I just installed server 18.04.1 LTS. The purpose of this server is to run scheduled Python scripts.

I can run my script just fine when authenticated with the user-account created during installation. But it won't run when scheduled with CRON (sudo crontab -e).

So... I set root password, authenticate and try running script and receive error "ModuleNotFoundError: No module named 'pandas'". So... I install pandas (sudo apt-get install python-pandas) and re-run. Same error

1
  • Please add output of pip freeze | grep pandas, su -c "pip freeze | grep pandas" and apt-cache policy python-pandas to the question. – N0rbert Jan 18 '19 at 21:39
0

Regardless of your purpose, tt's probably a safer choice to not use root to run any scripts on your server.

(I don't actually know if running cron scripts with root can create a vulnerability or not, but better safe than sorry i guess).

With that in mind, I think you could solve this by either

1) setting the permission for your user (the one that runs the script successfully) in the cron.allow file:

usually in the path /usr/lib/cron/cron.allow, simply adding the username in a separate line.

or

2) setting a custom env for the script:

HOME=user-home-directory
LOGNAME=user-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
PYTHONPATH=/usr/lib/pythonX.X

For more detailed information check this crontrab reference.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.