0

I have a python script that uses praw. When I run the script it works perfectly, but when I try to run in through crontab I continue to get:

import praw ImportError: No module named praw

I've tried everything I can think of and can't find any posts with the same issues. Not sure why it's doing this. Would appreciate any help, thank you.

Chamath
  • 2,016
  • 2
  • 21
  • 30
  • Try adding this line before the import statement: !pip install praw – JDSchenck Feb 15 '18 at 03:34
  • This question might help: https://stackoverflow.com/q/48597496/21945. Basically cron's environment is different to that of your terminal so you need to figure out what the pertinent differences are. – mhawke Feb 15 '18 at 03:36

1 Answers1

0

First create a python virtual environment with the specific python version you use. Then activate it and install your required packages using pip.

Then in your crontab you can first activate the virtual env and then run the python script you have. Either you can follow this or follow.

0 0 * * * /path/to/your/virtualenv/bin/python /absolute/path/for/your/python script>

Hope this helps!

Chamath
  • 2,016
  • 2
  • 21
  • 30