Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble running Python script CRON: Import Error: No Module Named Tweepy

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?

like image 945
SFC Avatar asked Aug 04 '17 19:08

SFC


People also ask

Why is my Python script not running in crontab?

The most likely reason is that your scripts require a resource or a service that's not yet available when cron is started.

Why crontab is not working?

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.

What is cron in Python?

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.


1 Answers

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.

like image 123
Robᵩ Avatar answered Oct 12 '22 23:10

Robᵩ