Python 使用任何 hg mercurial 命令时出现“错误:root:未找到哈希 md5 的代码”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59269208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:42:35  来源:igfitidea点击:

"ERROR:root:code for hash md5 was not found" when using any hg mercurial commands

pythonmacosopensslmercurialhomebrew

提问by poca

When trying to use any hgMercurial commands on the console, I keep getting this error. I installed Python using Homebrew and I am running Mac OS Catalina v. 10.15.1.

尝试hg在控制台上使用任何Mercurial 命令时,我不断收到此错误。我使用 Homebrew 安装了 Python,我正在运行 Mac OS Catalina v. 10.15.1。

Any reference would be appreciated. Here is the error I'm getting:

任何参考将不胜感激。这是我得到的错误:

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'

I also tried following the instruction on this issue but none of the solutions seem to work

我也尝试按照有关此问题的说明进行操作,但似乎没有任何解决方案有效

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

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

For pkg-config to find [email protected] you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"

回答by Rockallite

Running brew reinstall python@2didn't work for my existing Python 2.7 virtual environments. Inside them there were still ERROR:root:code for hash sha1 was not founderrors.

运行brew reinstall python@2不适用于我现有的 Python 2.7 虚拟环境。他们内部仍然存在ERROR:root:code for hash sha1 was not found错误。

I encountered this problem after I ran brew upgrade openssl. And here's the fix:

我跑了之后遇到了这个问题brew upgrade openssl。这是修复方法:

$ ls /usr/local/Cellar/openssl

...which shows

...这表现了

1.0.2t

According to the existing version, run:

根据现有版本,运行:

$ brew switch openssl 1.0.2t

...which shows

...这表现了

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

After that, run the following command in a Python 2.7 virtualenv:

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

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

...which shows

...这表现了

d41d8cd98f00b204e9800998ecf8427e

No more errors.

没有更多的错误。

回答by poca

Managed to fix this by first unlinking openssl

通过首先取消链接 openssl 设法解决了这个问题

brew unlink openssl

And then reinstalling python

然后重新安装python

brew reinstall python@2

I also noticed that when running 'brew doctor' there was a warning related to an openssl folder found in /usr/local/include/node/. I deleted this folder before running the above commands (not sure if related)

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

回答by Bingyu Shen

The case for me is that when I install dependencies of a django web app, it messes up the environment. When I type cd, it shows the same error.

我的情况是,当我安装 django Web 应用程序的依赖项时,它会弄乱环境。当我输入时cd,它显示相同的错误。

The problem was the openssllibrary, it can not find the correct ones.

问题是openssl图书馆,它找不到正确的图书馆。

If you are on Macintosh, you can type

如果您使用的是 Macintosh,则可以键入

ls /usr/local/Cellar/openssl

ls /usr/local/Cellar/openssl

to see all the versions,

查看所有版本,

brew switch openssl 1.0.XXXX

brew switch openssl 1.0.XXXX

to choose the available openssl version.

选择可用的 openssl 版本。

Then the error is gone :)

然后错误消失了:)

回答by user1766438

When I would import hashlib I would see an error message stating that hash md5 was not found.

当我导入 hashlib 时,我会看到一条错误消息,指出未找到 hash md5。

I was able to fix this problem by first unlinking openssl: brew unlink openssl

我能够通过首先取消链接 openssl 来解决这个问题: brew unlink openssl

Then I uninstalled python 2.7 using MacPorts: sudo port uninstall python27

然后我使用 MacPorts 卸载了 python 2.7: sudo port uninstall python27

Then I installed python 2.7 using MacPorts: sudo port install python27

然后我使用 MacPorts 安装了 python 2.7: sudo port install python27

Now importing hashlib works :)

现在导入 hashlib 工作:)

回答by Ravi D

Just uninstall python2

只需卸载python2

$ brew uninstall python@2

$ brew uninstall python@2

If there is any error :

如果有任何错误:

$ brew uninstall --ignore-dependencies python@2

$ brew uninstall --ignore-dependencies python@2

回答by Charles Merriam

I had this issue recently (2020, May) with Google's GCP CLI. It also works on the obsolete Python 2.7.

我最近(2020 年 5 月)在使用 Google 的 GCP CLI 时遇到了这个问题。它也适用于过时的 Python 2.7。

This is a borked Python 2 installation problem. mBrew no longer correctly installs Python 2 gracefully, as no one cares about abondonware.

这是一个无聊的 Python 2 安装问题。mBrew 不再正确地正确安装 Python 2,因为没有人关心 abondonware。

Conda still installs Python 2 in an environment; I did that.

Conda 仍然在环境中安装 Python 2;我就是这么做的。