当尝试在控制台上使用hg Mercurial命令时,我一直得到这个错误。 我使用Homebrew安装Python,运行的是Mac OS Catalina v. 10.15.1。

如有推荐,不胜感激。这是我得到的错误:

hg commit --amend
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, 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/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, 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/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, 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/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, 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/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, 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/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/usr/local/bin/hg", line 43, in <module>
    dispatch.run()
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 150, in __getattr__
    self._load()
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 94, in _load
    _origimport, head, globals, locals, None, level)
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 43, in _hgextimport
    return importfunc(name, globals, *args, **kwargs)
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/mercurial/dispatch.py", line 625, in <module>
    class lazyaliasentry(object):
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/mercurial/dispatch.py", line 636, in lazyaliasentry
    @util.propertycache
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 150, in __getattr__
    self._load()
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 94, in _load
    _origimport, head, globals, locals, None, level)
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 43, in _hgextimport
    return importfunc(name, globals, *args, **kwargs)
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/mercurial/util.py", line 180, in <module>
    'md5': hashlib.md5,
  File "/usr/local/Cellar/mercurial/4.9/lib/python2.7/site-packages/hgdemandimport/demandimportpy2.py", line 151, in __getattr__
    return getattr(self._module, attr)
AttributeError: 'module' object has no attribute 'md5'

我也试着按照这个问题的说明,但没有一个解决方案似乎工作

brew link openssl --force
Warning: Refusing to link macOS-provided software: openssl@1.1
If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

当前回答

设法解决这个问题,首先解除连接openssl

brew unlink openssl

然后重新安装python

brew reinstall python@2

我还注意到,当运行“brew doctor”时,在/usr/local/include/node/中发现了一个与openssl文件夹相关的警告。我在运行上述命令之前删除了这个文件夹(不确定是否相关)

其他回答

下一个解决方案适用于MacOS Catalina:

拆开openssl

brew unlink openssl

重新安装python 2.7(从homebrew中删除,不能通过brew install python@2安装)

brew tap-new <user>/homebrew-python2
brew extract python@2 <user>/homebrew-python2
brew reinstall /usr/local/Homebrew/Library/Taps/<user>/homebrew-python2/Formula/python@2.7.17.rbl

在macOS Mojave(10.14.6)上,这对我来说很有效:

在当前目录中保存该文件为python@2.rb。 酿造重新安装python@2.rb 我使用的是虚拟环境,所以我必须将它们链接回/usr/local/bin/python和/usr/local/bin/pip,用于python和pip二进制文件。

设法解决这个问题,首先解除连接openssl

brew unlink openssl

然后重新安装python

brew reinstall python@2

我还注意到,当运行“brew doctor”时,在/usr/local/include/node/中发现了一个与openssl文件夹相关的警告。我在运行上述命令之前删除了这个文件夹(不确定是否相关)

一个原因是:需要一个较旧的libssl

发生此错误时,Python无法导入_hashlib.py模块。其中一个原因是libssl在版本转换期间更改了它的ABI。这至少会影响Python2.7。

解决方案:下载libssl 1.1.0版本,编译并安装到另一个位置。然后在python的配置过程中告诉python使用这个旧的libssl库。

对我来说,python代码树的非标准前缀,如./configure——prefix=/home/anyuser/python就足够了(我将libssl安装到/usr/local),因为在通常的位置(/usr/local)中并行安装的旧libssl库会在配置和编译过程中自动找到并使用。

这是一个很好的例子,说明了为什么并行使用/usr和/usr/local目录。我一直在想这个问题。/usr用于标准系统的东西,/usr/local用于其他并行的东西。

在编译python2.7之后,终端中会出现一个摘要,告诉你在编译/链接过程中哪里出错了。应该不再有错过_hashlib的迹象。

对我来说,当我安装django web应用程序的依赖项时,它会把环境弄得一团糟。当我输入cd时,它显示了同样的错误。

问题是openssl库,它不能找到正确的。

如果你用的是Macintosh,你可以打字

ls / usr / local /地窖openssl

要查看所有版本,

打开openssl 1.0.XXXX

选择可用的openssl版本。

然后错误就消失了:)