【问题标题】:ERROR:root:code for hash md5 was not found错误:root:找不到哈希 md5 的代码
【发布时间】:2025-12-31 08:30:16
【问题描述】:

我在一台没有 root 访问权限的 Linux 机器上。我构建了自己的 openssl 和 python (2.7.13) 本地副本。当我尝试在 python 中导入 hashlib 时,我收到以下错误消息:

> python
Python 2.7.13 (default, Jan 22 2017, 19:23:53)
[GCC Intel(R) C++ gcc 4.8 mode] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/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 "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/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 "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/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 "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/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 "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/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 "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/user_jp/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512

更新:我刚刚意识到python构建未能构建hashlib模块:

building '_hashlib' extension
gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/p/home/user_jp/srcMisc/Python-2.7.13/INSTALL/include -I. -IInclude -I./Include -I/usr/lo
cal/include -I/p/home/user_jp/srcMisc/Python-2.7.13/Include -I/p/home/user_jp/srcMisc/Python-2.7.13 -c /p/home/user_jp/srcMisc/Python-2.7.13/Modules/_hashopenssl.c -o build/temp.linux-x8
6_64-2.7/p/home/user_jp/srcMisc/Python-2.7.13/Modules/_hashopenssl.o
In file included from /usr/include/openssl/asn1.h:74:0,
                 from /usr/include/openssl/objects.h:960,
                 from /usr/include/openssl/evp.h:98,
                 from /p/home/user_jp/srcMisc/Python-2.7.13/Modules/_hashopenssl.c:39:
/p/home/apps/gmpapp/gcc_dir/platform/gcc-4.8.4/lib/gcc/x86_64-unknown-linux-gnu/4.8.4/include-fixed/openssl/bn.h:610:1: error: unknown type name 'CRYPTO_THREADID'
 CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
 ^

我应该如何解决这个问题?看起来问题可能是它正在/usr/include/openssl 中寻找openssl 标头,但我正在尝试使用我自己安装的openssl。

【问题讨论】:

    标签: python


    【解决方案1】:

    想通了。 python 构建脚本在/usr/include 中查找openssl 头文件。由于我安装了自己的本地版本的 openssl,因此这些头文件是错误的。

    所以,我将 CFLAGS 设置为 -i/location/correct/openssl/header/files 并执行了 make distclean 并配置、构建并成功了。

    【讨论】:

      【解决方案2】:

      我认为这是在 OSX 的 vim 中使用 YouCompleteMe 时出现的第一个错误。这是在使用迁移助手从一台 Mac 迁移到另一台 Mac 之后,所以我没有进行全新安装。就我而言,这是因为 Anaconda python 发行版与 Homebrew 混淆了。

      正如brew doctor 警告我的那样,Anaconda 可能会导致 Homebrew 出现问题。所以我删除了路径中包含anaconda 的部分,然后运行:

      brew uninstall macvim
      brew install macvim
      brew linkapps
      

      Homebrew 抱怨 brew linkapps 不是一个好命令,但它对我仍然有效,并且我的 vim 错误消失了。

      【讨论】:

      • brew linkapps 自 2017 年 1 月左右以来已被弃用:不幸的是 brew linkapps 不能很好地与例如使用别名或符号链接和 Homebrew 公式的 Spotlight 不会构建可以重新定位的“正确”.app 包。相反,请考虑使用 brew cask 并使用 .apps 将公式迁移到 casks。
      【解决方案3】:

      我在 Ubuntu 16.04 上遇到过类似的问题。原来我需要这个包libssl-dev

      (错误:root:找不到哈希 md5 的代码。)

      【讨论】: