使用pip安装python包时遇到HTTPSHandler错误,以下是堆栈跟踪,
--------desktop:~$ pip install Django==1.3 Traceback (most recent call last): File "/home/env/.genv/bin/pip", line 9, inload_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 from pip.util import get_installed_distributions, get_prog File "/home/env/.genv/lib/python2.7/site-packages/pip/util.py", line 17, in from pip.vendor.distlib import version File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in from .compat import string_types File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in 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
这可能是由于升级到小牛队造成的.这就是我修复它的方法.
#make a copy of the existing library, just in case sudo cp /usr/bin/openssl /usr/bin/openssl.apple # update openssl brew update brew install openssl brew link --force openssl # reload terminal paths hash -r
brew uninstall python3 brew install python3 --with-brewed-openssl
brew uninstall python brew install python --with-brewed-openssl
这个答案整合了我发现的所有Stack Exchange答案和评论,主要基于Apple Stack Exchange的答案.
您可以获得配方的最新更新:
brew reinstall python
但是如果你仍然遇到问题,例如你可能已经升级了操作系统,那么你可能需要先获得最新的openssl.您可以从以下位置查看使用的版本和位置:
openssl version -a which openssl
要获得最新的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
附注:此警告表示对于其他应用,您可能需要使用
export LDFLAGS=-L/usr/local/opt/openssl/lib export CPPFLAGS=-I/usr/local/opt/openssl/include
然后重新编译python:
brew uninstall python brew install python --with-brewed-openssl
或者对于python 3
brew uninstall python3 brew install python3 --with-brewed-openssl
您需要在make之前安装OpenSSl并安装Python来解决问题.
在Centos上:
yum install openssl openssl-devel -y
资源
如果需要SSL支持,则需要在构建Python之前安装OpenSSL头文件.在Debian和Ubuntu上,它们位于一个名为的包中libssl-dev
.您可能需要更多依赖项,如此处所述.
即使在确认我的PATH等之后,我在Mac OSX上遇到了这个问题.
做了一个; 点击卸载virtualenv然后安装virtualenv它似乎现在有效.
当时我强迫brew连接openssl,取消关联它和virtualenv似乎仍然有用但也许那是因为它最初是在我重新安装时链接的.
对我来说这个问题的另一个症状是,如果我进入我的virtualenv的python控制台并且import ssl
它会错误.原来我的virtualenv没有使用brew
python版本,只是我机器上的默认安装.不知道为什么默认安装突然停止工作,但这是我如何修复它的问题:
rmvirtualenv myvirtualenv
brew update
brew reinstall python
mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv