I have a python script that runs fine when I am executing it from within a virtualenv but fails with the error "ImportError no module named oauthlib.oauth2..." I believe that the cron job needs to activate the virtual environment or that it is somehow related. I have tried many suggestions found on this site but without success. I am missing something and it's probably trivial. The cron job runs as root and the code is under a different user. I am not sure how to solve this. Your help is truly appreciated.
Asked
Active
Viewed 1,962 times
2
-
You're right, you have to tell cron to start (if it isn't already) and use the virtual env. – Steampunkery Feb 08 '17 at 15:29
-
I start the job and it runs the code but errors when it calls the module dependency "oauthlib.outh2" – Leo Feb 08 '17 at 15:39
-
What command are you telling cron to run? – Steampunkery Feb 08 '17 at 15:41
-
* * * * * /usr/bin/python /home/myusername/projects/wl01/wl_cron.py >> /tmp/cron_output 2>&1 – Leo Feb 08 '17 at 16:00
-
Thanks! I'll take a look. – Steampunkery Feb 08 '17 at 16:01
1 Answers
2
You can use the python that is in your virtualenv
like so:
/srv/.virtual/wl/bin/python /home/myusername/projects/wl01/wl_cron.py >> /tmp/cron_output 2>&1
Sources and References:

Steampunkery
- 3,839
- 2
- 19
- 28
-
-
-
I am receiving errors related to different parts of the code. But you have helped me get past the error related to my original question. – Leo Feb 08 '17 at 16:38