5

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?

SFC
  • 733
  • 2
  • 11
  • 22

3 Answers3

7

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.

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • I tried `sudo /usr/bin/pip install tweepy` but i get `command not found` – SFC Aug 04 '17 at 19:22
  • I also tried `/Users/eer/anaconda/bin/python MyScript.py` and I get `ERROR: unknown command MyScript.py` – SFC Aug 04 '17 at 19:27
  • 1
    1) So you don't have pip installed in your system. If you want to use pip to install tweepy into the system Python, you'll have to install pip first. I'm not sure how to install it in OSX (which I assume you are using.) 2) Give the full path to the script, just like you tried in the question: `/Users/eer/anaconda/bin/python /Users/eer/Desktop/myscript.py`. – Robᵩ Aug 04 '17 at 20:01
  • I still need to figure out how to install pip but `/Users/eer/anaconda/bin/python /Users/eer/Desktop/myscript.py` worked! thank you – SFC Aug 04 '17 at 21:05
  • @ER_18 - This might help: https://stackoverflow.com/questions/17271319/how-do-i-install-pip-on-macos-or-os-x – Robᵩ Aug 07 '17 at 16:28
0

Try to do a basic uninstall and then reinstall:

pip uninstall tweepy

and then:

pip install tweepy
liam
  • 1,918
  • 3
  • 22
  • 28
0

In Linux/Unix environment, cronjob usually runs with root privilege. You can check using the following command

ps -eF | grep cron

When installing tweepy, you might have installed as the normal user. Install tweepy as root and it should work.

sudo /usr/bin/pip3 install tweepy
s4n7h0
  • 123
  • 2
  • 7