I had this problem installing hashlib on OSX (El Capitan), after a failed pip install of hashlib and re-attemp using easy_install. After the event, I had errors just calling pip, let alone loading hashlib.
Root cause was pip adding a bad egg directory path to my sys.path and PYTHONHOME:
>>> import sys
>>> print sys.path
['', '/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg', '/Library/Python/2.7/site-packages/hashlib-20081119-py2.7-macosx-10.11-intel.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']
To fix, you can delete the file referenced directly, in my case:
rm /Library/Python/2.7/site-packages/hashlib-20081119-py2.7-macosx-10.11-intel.egg
I tried deleting just the directory reference, but after exploring here to identify the site.py and site_packages.py file belonging to my Current python version, which defines your paths, then looked at where site_packages.py was loading its paths from, it appears that the specific reference is added directly by pip? so the only workaround I could think of was to potentially hard code a line at the end of site.py to remove the reference, which I've seen on other threads.
hashlib
should be in the standard library. No need to install anything. – Mike Müller/usr/bin/python
, andhashlib
in/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py
. – 200_success