【问题标题】:Python 2.7 not working anymore: cannot import name md5Python 2.7 不再工作:无法导入名称 md5
【发布时间】:2018-06-01 17:42:40
【问题描述】:

我昨天在我的服务器(ubuntu 14.04)上安装了 python 3.6.3,现在我无法运行 python 2.7(在虚拟环境和“主环境”上)。

我一直在谷歌上寻找这个,但没有成功。

当我变红时,我尝试重新安装 openssl。

谁能帮帮我?我要疯了。

---> 这是我尝试执行 python 脚本(或 pip)时的消息:

*ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
 File "/usr/local/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/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/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/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/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/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/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 97, in     __get_builtin_constructoremphasized text
    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/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/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/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/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 "/var/www/QuantEngine/prod/QuantScripts/QuantEngineCli.py", line     11, in <module>
    from services import DataStructureManager, DatabaseFsHelper, Orchestra, BacktestManager
  File "/var/www/QuantEngine/prod/QuantScripts/services/__init__.py", line 8, in <module>
    from BuySellManager import BuySellManager
  File "/var/www/QuantEngine/prod/QuantScripts/services/BuySellManager.py", line 1, in <module>
    import requests
  File "/var/www/QuantEngine/venv/lib/python2.7/site-    packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/var/www/QuantEngine/venv/lib/python2.7/site-    packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/var/www/QuantEngine/venv/lib/python2.7/site-    packages/urllib3/connectionpool.py", line 29, in <module>
    from .connection import (
  File "/var/www/QuantEngine/venv/lib/python2.7/site-packages/urllib3/connection.py", line 39, in <module>
from .util.ssl_ import (
  File "/var/www/QuantEngine/venv/lib/python2.7/site-    packages/urllib3/util/__init__.py", line 6, in <module>
    from .ssl_ import (
  File "/var/www/QuantEngine/venv/lib/python2.7/site-    packages/urllib3/util/ssl_.py", line 7, in <module>
    from hashlib import md5, sha1, sha256
ImportError: cannot import name md5*

【问题讨论】:

  • 是我还是这条消息中有多个痕迹?您是否尝试过将pip install hashlib 作为 python2.7 您的当前目录?你的 python2.7 目录中有pip.exe 吗?
  • 当我尝试 pip install hashlib 时,我得到了这个回溯。我在 ubuntu 上,所以我没有 pip.exe,没有。
  • 尝试启动 python,然后在控制台输入import hashlib,然后输入dir(hashlib)。如果一切正常,hashlib._hashlib。现在作为测试:hashlib.sha1("").hexdigest(),然后是hashlib.sha384("").hexdigest()。至少其中一个会失败。进一步:import sslssl.OPENSSL_VERSION,查看自动使用的 OpenSSL 版本。之后在 _hashlib 动态模块上的 ldd (在我的盒子上是:/usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu。所以)

标签: python python-2.7 md5 python-import


【解决方案1】:

在这个post 可能是一个解决方案:

python2.7 包依赖于 libssl1_0_0 包(openssl_1.0 运行时库)。

所以你需要安装它,并在 $LD_LIBRARY_PATH 环境变量中添加 /usr/local/ssl/lib 目录。

【讨论】:

  • 是的,我试过了,但没有成功。我的服务器上没有 _hashlibmodule.so,我正在想办法找回它...
  • 你可以试试这个:python2.7 -v -c "import hashlib" 2> output.txt 。并复制粘贴缺少的内容
  • 由于某种原因失去了 SSH 访问权限。我正在构建一个新服务器,我将尝试重新启动该服务器(gunicorn 仍在运行)
【解决方案2】:

我在 macOS 上遇到了同样的问题。

brew reinstall python@2 解决了这个问题。

也许你可以尝试重新安装 python。

【讨论】:

  • 如果还是不行,你可能需要运行这个:curl https://raw.githubusercontent.com/Homebrew/homebrew-core/94d572a132a63651739fef1931f540404b7eaa31/Formula/python%402.rb &gt; python@2.rb; brew install python@2.rb
  • @trusktr 另一个提示您的解决方案!
  • @trusktr 非常感谢您修复了我之前在运行virtualenv venv 时生成 md5 错误的 python 2.7。这是固定的
  • @trusktr 的解决方案也对我有用,尽管我必须将 install python@2.rb 更改为 upgrade python@2.rb
  • 按照这个 SO 帖子的答案中的重新安装说明:link,以及重新安装 openssl@1.1 帮助我克服了这些 hashlib 错误。
【解决方案3】:

我在 macOS 中也遇到了同样的问题,我无法使用 brew reinstall python@2 命令解决。

然后我使用了以下对我有用的命令。

brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/94d572a132a63651739fef1931f540404b7eaa31/Formula/python%402.rb

【讨论】:

    【解决方案4】:

    我通过卸载自制 Python 2.7 解决了这个问题,而是从 python.org 安装了 Python 2.7.18。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2019-07-14
      • 2018-11-24
      • 1970-01-01
      • 2015-07-10
      • 2021-11-26
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      相关资源
      最近更新 更多