Tuesday, February 1, 2022

[SOLVED] ImportError: No module named tweepy

Issue

I installed pip in a virtual environment. It installed without errors. Here's what I get when I run sudo pip install tweepy after activating the venv:

Requirement already satisfied (use --upgrade to upgrade): tweepy in  
/usr/local/lib/python2.7/dist-packages/tweepy-3.1.0-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade): requests==2.4.3 in
/usr/local/lib/python2.7/dist-packages/requests-2.4.3-py2.7.egg (from tweepy)
Requirement already satisfied (use --upgrade to upgrade): requests-oauthlib==0.4.1 in 
/usr/local/lib/python2.7/dist-packages/requests_oauthlib-0.4.1-py2.7.egg (from tweepy)
Requirement already satisfied (use --upgrade to upgrade): six==1.7.3 in 
/usr/local/lib/python2.7/dist-packages/six-1.7.3-py2.7.egg (from tweepy)
Requirement already satisfied (use --upgrade to upgrade): oauthlib>=0.6.2 in 
/usr/local/lib/python2.7/dist-packages (from requests-oauthlib==0.4.1->tweepy)
Cleaning up...

So, I'm sure it worked.

When I run a sample tweepy script I get this error:

./twitterStream.py
Traceback (most recent call last):
  File "./twitterStream.py", line 6, in <module>
    import tweepy
ImportError: No module named tweepy

My script wasn't specifying any python interpreter. To make sure it wasn't looking else where I now specify the interpreter in the venv.

Any ideas?

Thanks!

more info:

if i use 'pip install tweepy' i get a whole bunch of errors:

(venv)user@ubuntu:~/code/twitterStream$ pip install tweepy
Traceback (most recent call last):
  File "/home/user/code/twitterStream/venv/bin/pip", line 9, in <module>
    load_entry_point('pip==1.1', 'console_scripts', 'pip')() 
  File "/home/user/code/twitterStream/venv/local/lib/python2.7/site-  
packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 337, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "/home/mukul/code/twitterStream/venv/local/lib/python2.7/site- 
packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 2279, in load_entry_point
    return ep.load()
  File "/home/user/code/twitterStream/venv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 1989, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/home/user/code/twitterStream/venv/local/lib/python2.7/site-packages/pip-1.1-  
py2.7.egg/pip/__init__.py", line 10, in <module>
    from pip.backwardcompat import walk_packages, console_to_str
  File "/home/user/code/twitterStream/venv/local/lib/python2.7/site-packages/pip-1.1-
py2.7.egg/pip/backwardcompat.py", line 77, in <module>
from urllib2 import URLError, HTTPError
  File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/lib/python2.7/httplib.py", line 79, in <module>
    import mimetools
  File "/usr/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: No module named _io

Edit: solved the errors thanks to: ImportError: No module named _io in ubuntu 14.04


Solution

Don't use sudo to call pip when you're in a virtualenv: the root user won't have the virtualenv activated so the package is installed globally, as you can see from the paths. Just run pip install tweepy.



Answered By - Daniel Roseman
Answer Checked By - David Goodson (WPSolving Volunteer)