本文介绍了导入错误:无法使用 PIP 导入名称 HTTPSHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pip安装python包时遇到HTTPSHandler错误,以下是堆栈跟踪,

Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,

--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
  File "/home/env/.genv/bin/pip", line 9, in <module>
    load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/home/env/.genv/lib/python2.7/site-packages/pip/__init__.py", line 10, in <module>
    from pip.util import get_installed_distributions, get_prog
  File "/home/env/.genv/lib/python2.7/site-packages/pip/util.py", line 17, in <module>
    from pip.vendor.distlib import version
  File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in <module>
    from .compat import string_types
  File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in <module>
    from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler

我曾经编辑 Modules/setup.dist 文件并取消注释 SSL 代码行并重建它,参考以下线程:http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html

I used to edit Modules/setup.dist file and uncomment SSL code lines and rebuilt it, with reference to following thread : http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html

推荐答案

OSX + homebrew 用户:

您可以获得食谱的最新更新:

OSX + homebrew users:

You can get the latest updates to the recipe:

brew reinstall python

但是如果您仍然遇到问题,例如也许您已经升级了您的操作系统,那么您可能需要先获取最新的 openssl.您可以从以下位置查看它的版本和使用位置:

But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:

openssl version -a
which openssl

获取最新的 openssl:

To get the latest openssl:

brew update
brew install openssl
brew link --overwrite --dry-run openssl  # safety first.
brew link openssl --overwrite

这可能会发出警告:

bash-4.3$ brew link --overwrite --dry-run openssl
Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

旁注:此警告意味着对于其他应用程序,您可能需要使用

Side note: this warning means that for other apps, you may want to use

export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include

然后重新编译python:

Then recompile python:

brew uninstall python
brew install python --with-brewed-openssl

或用于 python 3

or for python 3

brew uninstall python3
brew install python3 --with-brewed-openssl

这篇关于导入错误:无法使用 PIP 导入名称 HTTPSHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:15