73

I am using pip to install all my python packages but get error as shown in the trace below. What is the problem and how can I solve it?

usr@comp:~$ pip install flask
    Collecting flask
      Using cached Flask-0.11.1-py2.py3-none-any.whl
    Collecting itsdangerous>=0.21 (from flask)
      Using cached itsdangerous-0.24.tar.gz
    Collecting click>=2.0 (from flask)
      Using cached click-6.6.tar.gz
    Collecting Werkzeug>=0.7 (from flask)
      Using cached Werkzeug-0.11.11-py2.py3-none-any.whl
    Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/lib/python2.7/dist-packages (from flask)
    Requirement already satisfied (use --upgrade to upgrade): MarkupSafe in /usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
    THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
        Werkzeug>=0.7 from https://pypi.python.org/packages/a9/5e/41f791a3f380ec50f2c4c3ef1399d9ffce6b4fe9a7f305222f014cf4fe83/Werkzeug-0.11.11-py2.py3-none-any.whl#md5=c63a21eedce9504d223ed89358c4bdc9 (from flask):
        Expected md5 c63a21eedce9504d223ed89358c4bdc9
             Got        13a168aafcc43354b6c79ef44bb0dc71
davidism
  • 121,510
  • 29
  • 395
  • 339
Milla Tidy
  • 1,669
  • 1
  • 11
  • 11
  • Are you using a requirements file? This error suggests that you're using pip's hash checking mode and may be trying to upgrade a package's version without upgrading the hash first. – jonafato Oct 21 '16 at 19:58
  • No I am not explicitly using a requirements file but pip is checking flaks' dependencies using its (flask) requirements file. How do I make the hash upgrades? – Milla Tidy Oct 21 '16 at 20:12
  • Thanks to your comment jonafato, I fount a question from 2013 that has a solution that worked for me. The solution is in the answer below – Milla Tidy Oct 21 '16 at 20:21
  • check my answer in [this page](http://stackoverflow.com/questions/38028170/installing-python-packages-have-issue-in-md5/40400414#40400414) .. – Ahmad Tarbeya Nov 03 '16 at 11:48
  • Does this answer your question? [Why does pip fail with bad md5 hash for package?](https://stackoverflow.com/questions/16025788/why-does-pip-fail-with-bad-md5-hash-for-package) – Gino Mempin Nov 12 '22 at 03:16
  • I got this error after installing tensorflow, uninstalling it, and then trying to reinstall it. The selected answer solves it for me! – Anson Savage Dec 04 '22 at 04:50

13 Answers13

83

There is a similar problem (Why does pip fail with bad md5 hash for package?) from 2013 the solution that I tried that worked for me is this:

sudo pip install --no-cache-dir flask

given by attolee

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Milla Tidy
  • 1,669
  • 1
  • 11
  • 11
34

The problem here is the Python package was updated with new hash value while pip was trying to install the Python package using the old hash value cached in pip cache directory. This cache needs to be purge before the pip install attempt. So the full solution is:

python -m pip cache purge
python -m pip install <package>
Sergey Shubin
  • 3,040
  • 4
  • 24
  • 36
hstsvn
  • 384
  • 3
  • 5
  • When I try the command, I get the error: ERROR: pip cache commands can not function since cache is disabled. If cache is disabled, why am I getting the error? any idea? – PhaniBhushan kolla Oct 04 '22 at 18:16
17

--no-cache-dir did not work for me in raspberry pi 4 at first.

Found that the problem was due to unexpected network change/failure during pip installation

I had to download the broken .whl file manually with wget

and install it like below: sudo pip install scipy-1.3.0-cp37-cp37m-linux_armv7l.whl

followed by sudo pip install --no-cache-dir keras

Then it worked.

AdityaSrivast
  • 1,028
  • 1
  • 10
  • 16
rajava
  • 171
  • 1
  • 2
  • 1
    Using `--no-cache-dir` did not work for me. This did! But not sure what the real problem is though. Thanks for the instruction. – Abhi Jul 06 '19 at 14:27
  • 1
    This fixed my problem also for me on a Raspberry Zero! `sudo` shouldn't be necessary in general though. – iipr Jul 19 '19 at 08:09
10

Looks like a cache problem, the cached package is different from REQUIREMENTS.

Perhaps caused by last updates interruption.

I did this which fixed my problem:

rm ~/.cache/pip -rf
Jay
  • 738
  • 8
  • 14
9

You need to upgrade your pip into the newer version:

Using this command:

python -m pip install -upgrade pip

for Mac/Linux operating system and use

python -m pip install --upgrade tensorflow

for Windows to update your pip. Then run your command

 pip install flask
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
paul
  • 91
  • 1
  • 4
5

First, try to upgrade your pip then install the library:

python -m pip install --upgrade pip

If it didn't work, just try to install it without the cache:

pip install --no-cache-dir the_library_name
jared
  • 4,165
  • 1
  • 8
  • 31
HamzaElkotb
  • 138
  • 1
  • 7
5

In case you got this error while using pipenv try

$ pipenv --clear
$ pipenv lock
$ pipenv install
Levon
  • 10,408
  • 4
  • 47
  • 42
1

I had a similar issue for a different module. It was caused by network failure. My fix was nothing complex but another attempt at installing it and it worked.

Michael N
  • 31
  • 1
  • 2
0

maybe pipiserver(where you pip install from) upload a pkg for example flask-1.0.0.tar.gz, and rm is upload a new flask-1.0.0.tag.gz,if new pkg code has changed ,the hash must be different,there is two ways:

  1. installl an older pkg version =, pip install flask==0.0.9
  2. wait new pkg release flask==1.0.1 or cache expiration.
Saeed
  • 3,294
  • 5
  • 35
  • 52
Ginta
  • 151
  • 6
0

I have tried to clear pip cache with -m pip cache purge and using the --no-cache-dir argument but it was not helping.

In my case it was VPN being active during the attempts to install the package. As soon as I have turned it off everything worked as expected.

S.B
  • 13,077
  • 10
  • 22
  • 49
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 24 '23 at 01:58
0

The solution that worked for me:

    $ source .venv/Scripts/activate
    $ python -m pip install --upgrade pip
    $ python -m pip install <package> --no-cache-dir

If it does not work for some packages try to do this before the previous steps: https://stackoverflow.com/a/69668918/17596747

Then do the first 3 steps again.

UPD. Also maybe the problem is in VPN. Try to turn off/turn on VPN and see if this helps.

RasulOs
  • 41
  • 4
0

--no-cache-dir and cleaning the cash didn't work.

I installed .whl package through link in error text and installed it with pip install like: pip install Werkzeug-0.11.11-py2.py3-none-any.whl (in the same folder where it is downloaded).

After that everything worked with same pip install command that returned a error.

-1

This worked for me!

pip install --no-cache-dir flask --user