当尝试在控制台上使用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"

当前回答

运行brew重新安装python@2在我现有的Python 2.7虚拟环境中不起作用。其中仍然存在ERROR:root:code for hash sha1 was not found错误。

我在运行brew upgrade openssl后遇到了这个问题。下面是解决方案:

$ ls /usr/local/Cellar/openssl

...它显示了

1.0.2t

根据现有版本,执行:

$ brew switch openssl 1.0.2t

...它显示了

Cleaning /usr/local/Cellar/openssl/1.0.2t
Opt link created for /usr/local/Cellar/openssl/1.0.2t

之后,在Python 2.7 virtualenv中运行以下命令:

(my-venv) $ python -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"

...它显示了

d41d8cd98f00b204e9800998ecf8427e

不再有错误。

其他回答

我的问题是安装了多个版本的python (python仍然别名为python2,但我希望pip使用python3)。我的系统上还安装了python3 bin

# use pip with python3
$ python3 -m pip install fish

参见处理多个Python版本和PIP?有关详细信息,

对于我的例子,我只是使用pyenv重新安装python2

pyenv uninstall 2.7.18
pyenv install 2.7.18

然后一切似乎都联系起来了。

运行brew重新安装python@2在我现有的Python 2.7虚拟环境中不起作用。其中仍然存在ERROR:root:code for hash sha1 was not found错误。

我在运行brew upgrade openssl后遇到了这个问题。下面是解决方案:

$ ls /usr/local/Cellar/openssl

...它显示了

1.0.2t

根据现有版本,执行:

$ brew switch openssl 1.0.2t

...它显示了

Cleaning /usr/local/Cellar/openssl/1.0.2t
Opt link created for /usr/local/Cellar/openssl/1.0.2t

之后,在Python 2.7 virtualenv中运行以下命令:

(my-venv) $ python -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"

...它显示了

d41d8cd98f00b204e9800998ecf8427e

不再有错误。

我的问题是安装了pyenv并指向旧的python 2版本

卸载python@2 (python2自2020年1月1日起被EOL)

$ brew uninstall python@2
Uninstalling /usr/local/Cellar/python@2/2.7.15_1... (4,169 files, 76.0MB)

then

$ pyenv versions
  system
* 2.7.12 (set by /Users/admin/.python-version)
  3.4.5
  3.7.7

$ pyenv local system
$ pyenv global system

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

brew unlink openssl

然后重新安装python

brew reinstall python@2

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