MD5 import error in Python

From Exterior Memory
Jump to: navigation, search

I recently installed openssl 1.0 using a custom Macport.

After I did this, some Python scripts failed to work:

>>> import md5
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/md5.py", line 10, in <module>
    from hashlib import md5
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/hashlib.py", line 136, in <module>
    md5 = __get_builtin_constructor('md5')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor
    import _md5
ImportError: No module named _md5
>>> import _md5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named _md5

Of course, no real _md5 module exists.

I knew I screwed up, since I did some Ugly Tricks while installing openssl 1.0. However, I did not want to compiled Python from scratch, so I wanted to find out which library could not be found. Stuff like "otool -L" did not work, as the openssl library was only loaded after importing the hashlib library.

After some Googling, it turns, the error I was looking for is displayed with this Python code:

>>> import _hashlib
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_hashlib.so, 2): Library not loaded: /opt/local/lib/libssl.0.9.8.dylib
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_hashlib.so
  Reason: image not found

So that's it. /opt/local/lib/libssl.0.9.8.dylib was missing. With that info, I could revert my screw up and get a working Python version. Yeah.