Python “ImportError: No module named httplib2”即使在安装后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22735496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:31:06  来源:igfitidea点击:

"ImportError: No module named httplib2" even after installation

pythonpython-2.7piphttplib2

提问by Ben

I'm having a hard time understanding why I get ImportError: No module named httplib2after making sure httplib2 isinstalled. See below:

我有一个很难理解为什么我得到ImportError: No module named httplib2确保后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

I've also done

我也做过

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

PLUMBING! >shakes fist at heavens<

管道!>向天挥拳<

采纳答案by Ben

added this to .bash_profile export PATH=/usr/local/bin:$PATH

将此添加到 .bash_profile export PATH=/usr/local/bin:$PATH

then got:

然后得到:

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

can't say for sure why pipwas installing to /usr/localinstead of system default, but now they're the same, so it's working for now.

不能确定为什么pip安装到/usr/local而不是系统默认值,但现在它们是相同的,所以现在可以使用了。

回答by kenorb

If there are multiple Python instances (2 & 3), try different pip, for example:

如果有多个 Python 实例(2 & 3),请尝试不同的pip,例如:

Python 2:

蟒蛇2:

pip2 install httplib2 --upgrade

Python 3:

蟒蛇3:

pip3 install httplib2 --upgrade

To check what's installed and where, try:

要检查安装的内容和安装位置,请尝试:

pip list
pip2 list
pip3 list

Then make sure you're using the right Python instance (as suggested in the other answer).

然后确保您使用的是正确的 Python 实例(如其他答案中所建议)。

回答by Patrick

I faced similar problems on Windows 7. Here is how I solved it:

我在 Windows 7 上遇到了类似的问题。这是我的解决方法:

  1. Install Python: Simply download Pythonand follow the installation instructions of the wizard.
  2. Now, Python should be accessible from the command line. However, in my case, calling

    py script.py resulted in the the same error: "ImportError: No module named httplib2"

  3. I then had to add the Python and Pip installation paths to the "Path" environment variable in order to install the httplib2 module and then execute the script without failure. I followed the instructions provided here.

  4. Then I was able to execute

    pip3 install httplib2 --upgrade

  5. In the end I successfully managed to execute the script containing the httplib2 import statement.

  1. 安装 Python:只需下载 Python并按照向导的安装说明进行操作。
  2. 现在,应该可以从命令行访问 Python。但是,就我而言,调用

    py script.py 导致同样的错误:“ImportError: No module named httplib2”

  3. 然后我不得不将 Python 和 Pip 安装路径添加到“Path”环境变量中,以便安装 httplib2 模块,然后执行脚本而不会失败。我按照此处提供的说明进行操作。

  4. 然后我能够执行

    pip3 安装 httplib2 --upgrade

  5. 最后,我成功地执行了包含 httplib2 导入语句的脚本。

回答by Mahmoud

On Ubuntu:

在 Ubuntu 上:

Installing the library using the Ubuntu package manager fixed my issue:

使用 Ubuntu 包管理器安装库解决了我的问题:

sudo apt-get install python-httplib2