在OSX上出现Python/pip错误

24

最近我购买了一个新的硬盘并安装了一份干净的OS X Mavericks系统。我使用Homebrew安装了Python,现在需要创建一个Python虚拟环境。但是每当我尝试运行pip命令时,都会收到这个错误信息。我在网上找不到解决此问题的方法,希望能得到任何参考意见。以下是我遇到的错误信息:

ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 356, in load_entry_point
  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2439, in load_entry_point
  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2155, in load
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/__init__.py", line 10, in <module>
    from pip.util import get_installed_distributions, get_prog
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/util.py", line 18, in <module>
    from pip._vendor.distlib import version
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/version.py", line 14, in <module>
    from .compat import string_types
  File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/compat.py", line 31, in <module>
    from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler

如果您需要我提供额外信息,请告诉我。这是我第一次在此发布问题。谢谢。


1
你需要安装openssl - Padraic Cunningham
4个回答

57

好的,我发现在线上说这些错误与openssl有关。但我已经安装了openssl。经过更多的研究,我尝试了以下方法并解决了我的问题。如果你也遇到这个错误,这里是我的解决方案。

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

6
对我来说,brew reinstall python 就足够了(我从 https://dev59.com/N2Ij5IYBdhLWcg3wCxF0 得到了这个方法)。 - Piotr Migdal
1
在El Capitan上,对于我来说,只需要执行brew link openssl --force(确保首先安装了openssl)就足够了。 - Salyangoz
1
在OSX 10.11.3上,使用更新的Homebrew(版本>1.0.0,没有git存储库)和Homebrew/homebrew-core(git修订版2775;最后提交于2016-09-22),当我尝试强制链接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``` - Latrunculia
谢谢您,亲切的先生。 - jaredgorski
9
无效选项:--with-brewed-openssl - Aleksandar Pavić
显示剩余4条评论

3

由于执行 brew link openssl --force 时出现错误,我不得不手动添加库链接以使其运作。

brew update    
brew install openssl    
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/    
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
brew uninstall python
brew install python --with-brewed-openssl

3
上面的brew install openssl解决方案在使用Python 3时没有起作用。然后我意识到我安装的是Python 3.4.2,但是"No HTTPSHandler"异常正在查找/usr/local/Cellar/python3/3.4.1/...
在删除所有旧的Python 3路径并重新安装virtualenv后,它再次正常工作。
pip3 uninstall virtualenv
pip3 install virtualenv

请注意,install --upgrade 没有生效,需要先卸载。

1

当我尝试安装pygame时,发现在10.10上出现了同样的错误。通过brew remove python3然后从python.org安装python3.4.2以及active state tcl来解决它。

错误消失了 然后 pip3 install virtualenv

你会收到一个带有brew doctor的消息 警告:Python已安装在/Library/Frameworks/Python.framework下

Homebrew仅支持构建System-provided Python或brewed Python。特别是,安装在/Library下的Python可能会干扰其他软件的安装。

对我来说这并不重要,因为我更喜欢使用python.org的安装方式,这样python在各个平台上都是相同的,而不是在brew中存在差异(之前遇到过问题)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接