31

I'm on Solaris 10 (x86).

Until now, I was using python2.6. Today, I installed python2.7 and I have a weird error occuring when importing hashlib on 2.7, but not on 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

I don't understand why I have this error since I'm trying the import ON THE SAME MACHINE.

Thanks in advance for your help!

SuperPython
  • 915
  • 1
  • 8
  • 21
  • Perhaps because your hashlib version is for Python 2.6 only? Which version are you on? – aIKid Dec 05 '13 at 11:55
  • @alKid `hashlib` is a built-in module since Python 2.5 – tyteen4a03 Dec 05 '13 at 11:56
  • Also, duplicate of http://stackoverflow.com/questions/11433108/unsupported-hash-type-when-installing-plone – tyteen4a03 Dec 05 '13 at 11:57
  • Not really a duplicate, since my question is more generic. I don't understand the error: if it's related to OpenSSL, I should have the same error for the 2 versions of python. Why would it work for 2.6 and not for 2.7 with **the same openssl**? – SuperPython Dec 05 '13 at 12:08
  • 7
    run `python2.7 -v -c "import hashlib"` to see the list of what it is trying and failing to import. `ldd /usr/local/lib/python2.7/_hashlibmodule.so` tells you what?. i _suspect_ it is failing to load that due to how your locally compiled python2.7 was linked... – gps Dec 05 '13 at 22:44
  • @gps The `ldd /usr/local/lib/python2.7/_hashlibmodule.so` returns a `cannot open file: No such file or directory` error. The output of the first command is here: (http://pastebin.com/wbd1qAtv) Thank you for your help! ;) – SuperPython Dec 06 '13 at 06:38
  • @gps I found the _hashlib.so file in `/usr/local/lib/python2.7/lib-dynload/_hashlib.so`. I launched the ldd command on it and here's the result (in next comment). – SuperPython Dec 06 '13 at 07:30
  • The ldd result: `libssl.so.1.0.0 =>(file not found) libcrypto.so.1.0.0 =>(file not found) libpython2.7.so.1.0 =>/usr/local/lib/libpython2.7.so.1.0 libsocket.so.1 =>/usr/lib/libsocket.so.1 libnsl.so.1 =>/usr/lib/libnsl.so.1 librt.so.1 =>/usr/lib/librt.so.1 libdl.so.1 =>/usr/lib/libdl.so.1 libm.so.2 =>/usr/lib/libm.so.2 libc.so.1 =>/usr/lib/libc.so.1 libmp.so.2 =>/usr/lib/libmp.so.2 libmd.so.1 =>/usr/lib/libmd.so.1 libscf.so.1 =>/usr/lib/libscf.so.1 libaio.so.1 =>/usr/lib/libaio.so.1 libdoor.so.1 =>/usr/lib/libdoor.so.1 libuutil.so.1 =>/usr/lib/libuutil.so.1 libgen.so.1 =>/usr/lib/libgen.so.1` – SuperPython Dec 06 '13 at 07:32
  • So it seems that the files `libssl.so.1.0.0` and `libcrypto.so.1.0.0` are not "linked" correctly to the library. I did the same with python2.6 and found links to openssl_0.9.8 librairies. – SuperPython Dec 06 '13 at 07:41
  • The python2.7 packages is dependent to the libssl1_0_0 (openssl_1.0 runtime librairies). I installed it, and reinstalled python2.7, but the `libssl.so.1.0.0`and `libcrypto.so.1.0.0` files still appears as `(file not found)` in the `ldd` command output. – SuperPython Dec 06 '13 at 08:06

4 Answers4

23

The python2.7 package is dependent to the libssl1_0_0 package (openssl_1.0 runtime librairies).

I installed it, and added the /usr/local/ssl/lib directory in $LD_LIBRARY_PATH environnent variable.

And now it works perfectly! :)

SuperPython
  • 915
  • 1
  • 8
  • 21
13

same error for me. My case was a copied virtenv giving me this error on a new server. The default python was working.

I used

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

you should see something like this line below in your 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
...

So what I did is simply :

cp /usr/lib/python2.7/lib-dynload/_hashlib.so /*path-to-virtenv*/manager/lib/python2.7/lib-dynload/_hashlib.so
Bhavesh Odedra
  • 9,641
  • 12
  • 29
  • 57
martin
  • 452
  • 5
  • 14
11

You can use below command and check which libraries are missing,

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

e.g

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

If you get output like below, that means you are missing necessary openssl libraries

    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)
Karl Richter
  • 6,271
  • 17
  • 57
  • 120
Ishan Liyanage
  • 1,561
  • 19
  • 24
  • 1
    This example was a great help! I used the following to find all missing SOs in a paticular environment: `ldd /opt/test/python/lib/python2.7/lib-dynload/*.so | grep "not found"` – majgis Feb 23 '17 at 18:24
  • If SSL support wasn't compiled in you won't see these references - but their absence should tell you why it is failing. – andy_js Feb 11 '18 at 14:33
0

I know you're using Solaris, but I've followed these instructions to install the old libssl1.0-dev and it worked on Ubuntu 20.04.

Edit file /etc/apt/sources.list and add this line to the end of it.

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

After that run:

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

Finally,

sudo apt-get install libssl1.0-dev
Felipe Martim
  • 1,131
  • 10
  • 11