<p>在hashlib的pip安装失败后,我在OSX(El Capitan)上安装hashlib时遇到了这个问题,并使用easy_install重新尝试。事件发生后,我在调用pip时出错,更不用说加载hashlib了。</p>
<p>根本原因是pip向my sys.path和PYTHONHOME添加了一个坏蛋目录路径:</p>
<pre><code>>>> 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']
</code></pre>
<p>要修复此问题,可以删除直接引用的文件,在我的情况下:</p>
<pre><code>rm /Library/Python/2.7/site-packages/hashlib-20081119-py2.7-macosx-10.11-intel.egg
</code></pre>
<p>我尝试只删除目录引用,但是在研究了<a href="https://stackoverflow.com/questions/4271494/what-sets-up-sys-path-with-python-and-when">here</a>以标识属于我当前python版本的site.py和site_packages.py文件(它定义了您的路径),然后查看site_packages.py从何处加载其路径之后,似乎特定引用是由pip直接添加的?因此,我唯一能想到的解决办法是在site.py的末尾可能硬编码一行以删除引用,我在其他线程中也看到过这种情况。</p>