Background: I am following Crontab not running my python script in an attempt to debug and run my python script using CRON. Per SO suggestions, I tried /usr/bin/python /Users/eer/Desktop/myscript.py
on the terminal.
Problem: However, I get a an error: ImportError: No module named tweepy
. So, I tried to pip install tweepy
and I get the following:Requirement already satisfied: tweepy in /Users/eer/anaconda/lib/python2.7/site-packages
. So it seems I have tweepy but when I /usr/bin/python /Users/eer/Desktop/myscript.py
it doesn't seem to read it. Suggestions?
The most likely reason is that your scripts require a resource or a service that's not yet available when cron is started.
Why is crontab not working in your system? Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.
Cron is a Unix-like operating system software utility that allows us to schedule tasks. Cron's tasks are specified in a Crontab, which is a text file that contains the instructions to run. The Crontab module in Python allows us to handle scheduled operations using Cron.
Your /usr/bin/python MyScript.py
command and your pip
command are invoking two different python interpreters. Try either:
/Users/eer/anaconda/bin/python MyScript.py
or
/usr/bin/pip install tweepy
The former will invoke your personal Python interpreter, the one that already has tweepy
installed. The latter will install tweepy
for the system-wide Python.
You may need to invoke the latter option as root, for example, sudo /usr/bin/pip install tweepy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With