Python packages hash not matching whilst installing using pip

Question:

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
Asked By: Milla Tidy

||

Answers:

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

Answered By: Milla Tidy

--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.

Answered By: rajava

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
Answered By: paul

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
Answered By: Jay

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.

Answered By: Michael N

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
Answered By: HamzaElkotb

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>
Answered By: hstsvn

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.
Answered By: Ginta

In case you got this error while using pipenv try

$ pipenv --clear
$ pipenv lock
$ pipenv install
Answered By: Levon

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.

Answered By: kknczny

This worked for me!

pip install --no-cache-dir flask --user
Answered By: Abiot Sibanda

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.

Answered By: RasulOs

--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.

Answered By: Tim Foxers

Try:

rm -rf "$(pip cache dir)"

And if you’re using conda:

conda clean --all
Answered By: Narek

If your pip is version 3 then you should try:
pip3 install <package name>

Answered By: Yasin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.