我在虚拟环境中安装了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中指定解释器的地方。
有任何想法吗?
谢谢!
更多信息:
如果我使用“ pip install tweepy”,则会收到很多错误:
(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:Ubuntu 14.04中没有名为_io的模块
sudo当您进入virtualenv时,不要使用pip调用:root用户不会激活virtualenv,因此该软件包是全局安装的,正如您从路径中看到的那样。快跑pipinstall tweepy。
sudo
pipinstall tweepy