首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在python 2.7中导入hashlib时出错,但在2.6中不是

在python 2.7中导入hashlib时出错,但在2.6中不是
EN

Stack Overflow用户
提问于 2013-12-05 19:53:36
回答 4查看 85.9K关注 0票数 31

我在Solaris10 (x86)上。

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

Python 2.6:

代码语言:javascript
复制
root@myserver [PROD] # python2.6 -c "import hashlib"
root@myserver [PROD] # 

Python 2.7:

代码语言:javascript
复制
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

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

提前感谢您的帮助!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-12-06 16:15:17

Openssl_1.0 2.7包依赖于python2.7包(python2.7运行时库)。

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

现在它完美地工作了!:)

票数 24
EN

Stack Overflow用户

发布于 2014-07-26 06:30:06

我也犯了同样的错误。我的案例是一个复制的virtenv,在一个新的服务器上给了我这个错误。默认的python运行正常。

我用过

代码语言:javascript
复制
python2.7 -v -c "import hashlib" 2> output.txt

您应该会在output.txt中看到类似下面这一行的内容

代码语言:javascript
复制
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
...

所以我所做的很简单:

代码语言:javascript
复制
cp /usr/lib/python2.7/lib-dynload/_hashlib.so /*path-to-virtenv*/manager/lib/python2.7/lib-dynload/_hashlib.so
票数 14
EN

Stack Overflow用户

发布于 2015-02-24 10:48:27

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

代码语言:javascript
复制
ldd /path/to/Python-Library/_hashlibmodule.so

e.g

代码语言:javascript
复制
ldd /usr/local/lib/python2.7/_hashlibmodule.so

如果您得到如下所示的输出,这意味着您缺少必要的openssl库

代码语言:javascript
复制
    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)
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20399331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档