33

I installed python 3.6.3 on my server yesterday (ubuntu 14.04), and now I cannot run python 2.7 (in the virtual envs and on the 'main env').

I've been looking around google for this, without success.

I tried to re-intall openssl as I red.

Can anyone help me ? I'm going mad.

---> Here is the message whenever i tried to execute a python script (or 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*
Selcuk
  • 57,004
  • 12
  • 102
  • 110
JulienCoo
  • 1,128
  • 3
  • 13
  • 24
  • Is it me or there are multiple traces in this message ? Have you tried doing `pip install hashlib` as python2.7 your current directory ? And is there a `pip.exe` in your python2.7 dir ? – IMCoins Dec 19 '17 at 10:11
  • I get this traceback when i try a pip install hashlib. and i'm on ubuntu so I don't have a pip.exe, no. – JulienCoo Dec 19 '17 at 10:25
  • Try launching _python_, and type in the console `import hashlib`, then `dir(hashlib)`. Then if everything is fine, `hashlib._hashlib`. Now as a test: `hashlib.sha1("").hexdigest()` and then `hashlib.sha384("").hexdigest()`. At least one of those will fail. Further: `import ssl`, `ssl.OPENSSL_VERSION`, to see what _OpenSSL_ version is being automatically used. Even more after that a `ldd` on the *\_hashlib* dynamic module (on my box it's: */usr/lib/python2.7/lib-dynload/\_hashlib.x86\_64-linux-gnu.so*) – CristiFati Dec 21 '17 at 17:42

4 Answers4

44

I had the same problem on macOS.

brew reinstall python@2 solved this problem.

Maybe you could try to reinstall python.

Emma
  • 27,428
  • 11
  • 44
  • 69
recluse
  • 459
  • 4
  • 8
  • 24
    If that still doesn't work, you may need to run this: `curl https://raw.githubusercontent.com/Homebrew/homebrew-core/94d572a132a63651739fef1931f540404b7eaa31/Formula/python%402.rb > python@2.rb; brew install python@2.rb` – trusktr Mar 25 '20 at 04:27
  • 3
    @trusktr Another tip o' the hat for your solution! – Chas Brown May 07 '20 at 00:56
  • 2
    @trusktr Brilliant thanks for fixing my python 2.7 that previously generated md5 error when running `virtualenv venv`. That's fixed – vintagexav Oct 14 '20 at 13:59
  • 1
    The solution from @trusktr worked for me as well, though I did have to change `install python@2.rb` to `upgrade python@2.rb` – taylor Nov 13 '20 at 05:15
  • Following the reinstall instructions in the answer on this SO post: [link](https://stackoverflow.com/questions/60298514/how-to-reinstall-python2-from-homebrew) , along with reinstall of openssl@1.1 worked to get me past these hashlib errors. – Wayne Jan 31 '21 at 19:16
3

In this post might be a solution:

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

So you need to install it, and add the /usr/local/ssl/lib directory in $LD_LIBRARY_PATH environnent variable.

Vasily Bronsky
  • 435
  • 2
  • 12
  • Yes i tried that, without success. I don't have _hashlibmodule.so on my server, i'm trying to figure how to get it back... – JulienCoo Dec 19 '17 at 11:06
  • can you try this: python2.7 -v -c "import hashlib" 2> output.txt . And copy paste what's missing – Vasily Bronsky Dec 19 '17 at 11:46
  • lost SSH access for some reason. I'm building a new server, and I will try to restart that one (gunicorn is still up and running) – JulienCoo Dec 19 '17 at 16:16
0

I too came across the same issue in macOS which I could not solve using the brew reinstall python@2 command.

So then I used the following command which worked for me.

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

Keshav Lodhi
  • 2,641
  • 2
  • 17
  • 23
0

I solved it by uninstalling the homebrew Python 2.7, and instead installing Python 2.7.18 from python.org.