4

While trying to install pip, virtualenv the following error occurs.

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

How can I solve the Hashmissing error? Tried through HTTPSHandler link.

Simon Woodside
  • 7,175
  • 5
  • 50
  • 66
the-run
  • 977
  • 1
  • 10
  • 21

3 Answers3

0

I've had a similar problem. In my case it was after a system upgrade and “repairing” a virtualenv according to https://www.guyrutenberg.com/2012/05/30/fixing-virtualenv-after-upgrading-your-distributionpython/, ie. running virtualenv over it again. As I see it now, this merges two versions of pip and setuptools by overwriting some files and creating a broken mess. My solution is to remove pip and setuptools manually from virtualenv’s site-packages and then running virtualenv to repair.

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

In your case it is not virtualenv, but I think the cause is similar (two pip versions one over the other).

audeoudh
  • 1,279
  • 1
  • 8
  • 23
janek37
  • 572
  • 5
  • 16
0

Answer below is good, with one fix - must use 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
skabbit
  • 96
  • 1
  • 6
-3

No such class 'HashMissing' in Python 2.7 so you get this error.

Why not just import pip.exceptions 'as is'?

egur
  • 7,830
  • 2
  • 27
  • 47
  • 3
    It's was not clear from the original post (my edit is still pending), but the import happens in code that is not under the users control, so they cannot simple change the import line. – Fabian Mar 30 '17 at 14:04