2014-03-29 86 views
25

我很難理解在確認httplib2 安裝了之後我爲什麼得到ImportError: No module named httplib2。請看下圖:「ImportError:No module named httplib2」即使安裝後

$ which -a python 
/usr/bin/python 
/usr/local/bin/python 

$ pip -V 
pip 1.4.1 from /usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7 

$ pip list 
google-api-python-client (1.2) 
httplib2 (0.8) 
pip (1.4.1) 
pudb (2013.5.1) 
Pygments (1.6) 
setuptools (1.3.2) 
wsgiref (0.1.2) 

$ pip install httplib2 
Requirement already satisfied (use --upgrade to upgrade): httplib2 in /usr/local/lib/python2.7/site-packages 
Cleaning up... 

$ python 
Python 2.7.5 (default, Sep 12 2013, 21:33:34) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import httplib2 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
ImportError: No module named httplib2 

我也做

$ find/| grep httplib2 
/usr/local/lib/python2.7/site-packages/httplib2 
/usr/local/lib/python2.7/site-packages/httplib2/__init__.py 
[... edited for brevity] 

管道! >動搖拳頭在天堂<

+1

你可以做一個'哪個python'嗎? – poke

+1

ahhh ...我seeeeeeee .... – Ben

+1

你看到了什麼? :D – poke

回答

13

將此添加到.bash_profile中 ​​

然後起身:

$ which -a python 
/usr/local/bin/python 
/usr/bin/python 
/usr/local/bin/python 
$ python 
Python 2.7.6 (default, Dec 27 2013, 14:07:24) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import httplib2 
>>> 

不能肯定地說,爲什麼pip被安裝到/usr/local而不是系統默認的,但現在他們是一樣的,所以它現在工作。

26

如果有多個Python的實例(2 & 3),嘗試不同的pip,例如:

的Python 2:

pip2 install httplib2 --upgrade 

的Python 3:

pip3 install httplib2 --upgrade 

要檢查什麼安裝在哪裏,試試:

pip list 
pip2 list 
pip3 list 

然後確保您使用的是正確的Python實例(如other answer中所建議的)。

+5

謝謝你的回答。「--upgrade」很重要。 –