如何在python 2.7中使用pip解决HashMissing?

问题描述 投票:4回答:3

在尝试安装pip时,virtualenv发生以下错误。

Traceback (most recent call last):   
      File "/usr/local/bin/pip", line 7, in <module>
        from pip import main 
      File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 63, in <module>
        from pip.commands import commands, get_summaries, get_similar_commands
      File "/usr/lib/python2.7/dist-packages/pip/commands/__init__.py", line 6, in <module>
        from pip.commands.bundle import BundleCommand  
      File "/usr/lib/python2.7/dist-packages/pip/commands/bundle.py", line 6, in <module>
        from pip.commands.install import InstallCommand   
      File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 5, in <module>
        from pip.req import InstallRequirement, RequirementSet, parse_requirements   
      File "/usr/lib/python2.7/dist-packages/pip/req/__init__.py", line 3, in <module>
        from .req_install import InstallRequirement  
      File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 42, in <module>
        from pip.utils.hashes import Hashes   
      File "/usr/lib/python2.7/dist-packages/pip/utils/hashes.py", line 5, in <module>
        from pip.exceptions import HashMismatch, HashMissing, InstallationError
    ImportError: cannot import name HashMissing

我怎样才能解决Hashmissing错误?通过HTTPSHandler link尝试。

python-2.7 pip virtualenv
3个回答
0
投票

我有类似的问题。在我的情况下,它是在系统升级和“修复”virtualenv根据https://www.guyrutenberg.com/2012/05/30/fixing-virtualenv-after-upgrading-your-distributionpython/,即。再次运行virtualenv。正如我现在看到的那样,它通过覆盖一些文件并创建一个破碎的混乱来合并两个版本的pipsetuptools。我的解决方案是从pipsetuptools手动删除virtualenvsite-packages,然后运行virtualenv进行修复。

VENV_DIR="<your venv dir>"
rm -r "$VENV_DIR"/lib/python2.7/site-packages/{pip,setuptools} "$VENV_DIR"/lib/python2.7/site-packages/setuptools-* "$VENV_DIR"/lib/python2.7/site-packages/pip-*
virtualenv "$VENV_DIR"
source "$VENV_DIR"/bin/activate
pip install -U pip setuptools

在你的情况下它不是virtualenv,但我认为原因是相似的(两个pip版本一个在另一个)。


0
投票

下面的答案是好的,有一个修复 - 必须使用pip2:

VENV_DIR="<your venv dir>"
rm -r "$VENV_DIR"/lib/python2.7/site-packages/{pip,setuptools} "$VENV_DIR"/lib/python2.7/site-packages/setuptools-* "$VENV_DIR"/lib/python2.7/site-packages/pip-*
virtualenv "$VENV_DIR"
source "$VENV_DIR"/bin/activate
pip2 install -U pip setuptools

-3
投票

在Python 2.7中没有这样的类'HashMissing',所以你得到这个错误。

为什么不只是import pip.exceptions'原样'?

© www.soinside.com 2019 - 2024. All rights reserved.