使用python 2.7导入hashlib时出错,但不能导入2.6

时间:2013-12-05 11:53:36

标签: python python-2.7 solaris solaris-10 hashlib

我在Solaris 10(x86)上。

到现在为止,我使用的是python2.6。今天,我安装了python2.7,在2.7上导入hashlib时出现了一个奇怪的错误,但在2.6上没有:

Python 2.6:

root@myserver [PROD] # python2.6 -c "import hashlib"
root@myserver [PROD] # 

Python 2.7:

root@myserver [PROD] # python2.7 -c "import hashlib"
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, 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 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, 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 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, 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 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, 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/lib/python2.7/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, 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 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512

我不明白为什么我有这个错误,因为我正在尝试导入在同一台机器上

提前感谢您的帮助!

4 个答案:

答案 0 :(得分:18)

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

我安装了它,并在/usr/local/ssl/lib environnent变量中添加了$LD_LIBRARY_PATH目录。

现在它完美无缺! :)

答案 1 :(得分:12)

您可以使用以下命令并检查缺少哪些库,

ldd /path/to/Python-Library/_hashlibmodule.so

e.g

ldd /usr/local/lib/python2.7/_hashlibmodule.so

如果您得到如下所示的输出,则表示您缺少必要的openssl库

    linux-vdso.so.1 =>  (0x00007fffd6f6a000)
    libssl.so.6 => not found
    libcrypto.so.6 => not found
    libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007ffb18b54000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ffb18937000)
    libc.so.6 => /lib64/libc.so.6 (0x00007ffb185a2000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007ffb1839e000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007ffb1819b000)
    libm.so.6 => /lib64/libm.so.6 (0x00007ffb17f16000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003e0a000000)

答案 2 :(得分:6)

对我来说同样的错误。我的情况是复制virtenv在新服务器上给我这个错误。默认的python正在运行。

我用过

python2.7 -v -c "import hashlib" 2> output.txt

您应该在output.txt

中看到以下内容
import hashlib # precompiled from hashlib.pyc
dlopen("/path/to/virtenv/lib/python2.7/lib-dynload/_hashlib.so", 2);

ldd /path/to/virtenv/lib/python2.7/lib-dynload/_hashlib.so
...
   libssl.so.0.9.8 => not found
   libcrypto.so.0.9.8 => not found
...

所以我所做的只是:

cp /usr/lib/python2.7/lib-dynload/_hashlib.so /*path-to-virtenv*/manager/lib/python2.7/lib-dynload/_hashlib.so

答案 3 :(得分:0)

我知道您使用的是 Solaris,但我已经按照 these instructions 安装了旧的 libssl1.0-dev 并且它在 Ubuntu 20.04 上运行。

编辑文件 /etc/apt/sources.list 并将此行添加到它的末尾。

deb http://security.ubuntu.com/ubuntu bionic-security main

在那之后运行:

sudo apt update && apt-cache policy libssl1.0-dev

最后,

sudo apt-get install libssl1.0-dev