ImportError:没有名为tweepy的模块

时间:2014-12-12 20:06:08

标签: python virtualenv python-import tweepy

我在虚拟环境中安装了pip。它安装没有错误。这是我在激活venv后运行sudo pip install tweepy时得到的结果:

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...

所以,我确定它有效。

当我运行示例tweepy脚本时,我收到此错误:

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

我的脚本没有指定任何python解释器。为了确保它没有找到我现在在venv中指定解释器的地方。

有什么想法吗?

谢谢!

更多信息:

如果我使用&#39; pip install tweepy&#39;我得到了一大堆错误:

(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

编辑:通过以下方式解决了错误:ImportError: No module named _io in ubuntu 14.04

3 个答案:

答案 0 :(得分:2)

当您使用virtualenv时,不要使用sudo来调用pip:root用户不会激活virtualenv,因此可以从路径中看到全局安装包。只需运行pip install tweepy

答案 1 :(得分:-1)

由于您使用的是virtualenv,因此您无需使用sudo

答案 2 :(得分:-1)

用于安装tweepy模块 只需写pip install tweepy即可使用