Search code examples
pythonopencvraspberry-piraspbian

"pipenv install opencv-python" fails on fresh Raspbian installation


On a fresh install of Raspbian (Buster), I installed pip3:

sudo -H pip3 install pipenv

Then inside a new directory, install opencv-python (latest version of 3.x in my case):

pipenv install opencv-python==3.4.4.19

Which ends with an error about mismatched hashes:

pipenv install opencv-python==3.4.4.19
Creating a virtualenv for this project…
Pipfile: /home/pi/code/test3/Pipfile
Using /usr/bin/python3 (3.7.3) to create virtualenv…
⠴ Creating virtual environment...Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/pi/.local/share/virtualenvs/test3-D0e_lqS8/bin/python3
Also creating executable in /home/pi/.local/share/virtualenvs/test3-D0e_lqS8/bin/python
Installing setuptools, pip, wheel...
done.

✔ Successfully created virtual environment! 
Virtualenv location: /home/pi/.local/share/virtualenvs/test3-D0e_lqS8
Creating a Pipfile for this project…
Installing opencv-python==3.4.4.19…
Adding opencv-python to Pipfile's [packages]…
✔ Installation Succeeded 
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success! 
Updated Pipfile.lock (6fb88c)!
Installing dependencies from Pipfile.lock (6fb88c)…
An error occurred while installing numpy==1.16.4 --hash=sha256:0778076e764e146d3078b17c24c4d89e0ecd4ac5401beff8e1c87879043a0633 --hash=sha256:141c7102f20abe6cf0d54c4ced8d565b86df4d3077ba2343b61a6db996cefec7 --hash=sha256:14270a1ee8917d11e7753fb54fc7ffd1934f4d529235beec0b275e2ccf00333b --hash=sha256:27e11c7a8ec9d5838bc59f809bfa86efc8a4fd02e58960fa9c49d998e14332d5 --hash=sha256:2a04dda79606f3d2f760384c38ccd3d5b9bb79d4c8126b67aff5eb09a253763e --hash=sha256:3c26010c1b51e1224a3ca6b8df807de6e95128b0908c7e34f190e7775455b0ca --hash=sha256:52c40f1a4262c896420c6ea1c6fda62cf67070e3947e3307f5562bd783a90336 --hash=sha256:6e4f8d9e8aa79321657079b9ac03f3cf3fd067bf31c1cca4f56d49543f4356a5 --hash=sha256:7242be12a58fec245ee9734e625964b97cf7e3f2f7d016603f9e56660ce479c7 --hash=sha256:7dc253b542bfd4b4eb88d9dbae4ca079e7bf2e2afd819ee18891a43db66c60c7 --hash=sha256:94f5bd885f67bbb25c82d80184abbf7ce4f6c3c3a41fbaa4182f034bba803e69 --hash=sha256:a89e188daa119ffa0d03ce5123dee3f8ffd5115c896c2a9d4f0dbb3d8b95bfa3 --hash=sha256:ad3399da9b0ca36e2f24de72f67ab2854a62e623274607e37e0ce5f5d5fa9166 --hash=sha256:b0348be89275fd1d4c44ffa39530c41a21062f52299b1e3ee7d1c61f060044b8 --hash=sha256:b5554368e4ede1856121b0dfa35ce71768102e4aa55e526cb8de7f374ff78722 --hash=sha256:cbddc56b2502d3f87fda4f98d948eb5b11f36ff3902e17cb6cc44727f2200525 --hash=sha256:d79f18f41751725c56eceab2a886f021d70fd70a6188fd386e29a045945ffc10 --hash=sha256:dc2ca26a19ab32dc475dbad9dfe723d3a64c835f4c23f625c2b6566ca32b9f29 --hash=sha256:dd9bcd4f294eb0633bb33d1a74febdd2b9018b8b8ed325f861fffcd2c7660bb8 --hash=sha256:e8baab1bc7c9152715844f1faca6744f2416929de10d7639ed49555a85549f52 --hash=sha256:ec31fe12668af687b99acf1567399632a7c47b0e17cfb9ae47c098644ef36797 --hash=sha256:f12b4f7e2d8f9da3141564e6737d79016fe5336cc92de6814eba579744f65b0a --hash=sha256:f58ac38d5ca045a377b3b377c84df8175ab992c970a53332fa8ac2373df44ff7! Will try again.
An error occurred while installing opencv-python==3.4.4.19 --hash=sha256:18bc3a32995215f77740dbe491990ea91772b1afa585431fd6e916e0a5f759b2 --hash=sha256:19a1cbeaef79592c74c5051fa54933dd36bdd4d690df9f69a3da9fa0053bb49a --hash=sha256:1baac6bdf28c817e1446ad1cab938d685456053708fb64722b95c0108e126fe1 --hash=sha256:26efbd00b17fcdd9eef9ba79ac6f280694b519cfdacbd7965f521f521c83a74f --hash=sha256:2a7d93fcd61294b014f653084295920edf1fb1c36d7a68a287cc2b4a4b2399e1 --hash=sha256:2ff1900511bbb948418a20d20501eee33eed035fde3c5aad5e305123f1e98fbe --hash=sha256:33e021aad18f40bfae2efb3431708bb29ddcba7c6a9199297f5832468e6bc772 --hash=sha256:3b59036967f015b6fe381b9e8c3836ac4056045988f83d09e8644a71908ceca9 --hash=sha256:4cb787d796fcbff36c40d4bff9d7ee00ec1bb4c059b907aee6ad0d61b4633808 --hash=sha256:4f83451dc1857c4bfa0096bc5e720530f71e99787e66a315fe6901c0d15331cf --hash=sha256:518b7b81df7ef0731714ad0363968649c60071b9072cdbc64efc1672d4f574e8 --hash=sha256:526c9b23b649184f2b0a2c8f8000ecfbe3d7da354ed74c8aec87d6878656361e --hash=sha256:6f36ab695bc43c62a11276b6de4253898afa064a2a13d569bd7939c63b0eed4d --hash=sha256:72f3c9dc4b0016a6e1135fb1549da8445851cb790e0020a217fe28ad8dad76e0 --hash=sha256:7383c413a96e64a301b3906ffddd6bc2105c81966ad52f8aaa2835446ad4ed4f --hash=sha256:80f2feab5e9ba3f0ba3788a7162c7733ba4524e2ac001c20fd63af1cb9626625 --hash=sha256:8d945a9544287949c70bcf23ce8a09724f50adc365f22ff28a77d9427ef74238 --hash=sha256:9adfc5ad89cb4ea4afa445494138cef79316adf7e45cea467ee1ea09571bd31c --hash=sha256:9d3e53880d9ef9f7838fb2a54fa576466329fbc67d27a4c99aac7971e290ab26 --hash=sha256:9f7754a877ec0de3e8dcaf7d99e23b2d3114b057087100424d5772b6e7564abe --hash=sha256:a4de364e46d68f4eb392219a5135d3b8470926fddd264415b3524566bbf50782 --hash=sha256:a4e1c9df81c9d13ea7711141d1cee96def112a199ccc76212a8e7a65b7a4e658 --hash=sha256:b43e3079a85efbff04ced76445b75dd3ee220b4251ac83cb1750fad9cf445f3d --hash=sha256:d1df5005261ae44597d9bccf5317fcdccfdc1083525ef24884bb5c066d1ab4ba --hash=sha256:d48ca719e8ab5c41238da398830cbe3e482cce0dc0f0b9ade033f86d595ecc98 --hash=sha256:e20c771adcd8867aeca7df8605f26bdabbab41895efdac8fe602a3203438b025 --hash=sha256:f6952b0ccce36c4f6a25441164e6ff89298c716547ff23c4862b7e91300714a6! Will try again.
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 2/2 — 00:00:17
Installing initially failed dependencies…
  ☤  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 2/2 — 00:00:14
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/dist-packages/pipenv/cli/command.py", line 254, in install
[pipenv.exceptions.InstallError]:       editable_packages=state.installstate.editables,
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/dist-packages/pipenv/core.py", line 1992, in do_install
[pipenv.exceptions.InstallError]:       skip_lock=skip_lock,
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/dist-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/dist-packages/pipenv/core.py", line 862, in do_install_dependencies
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, False, failed_deps_queue, retry=False)
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/dist-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple', 'Collecting numpy==1.16.4 (from -r /tmp/pipenv-t5vvgr38-requirements/pipenv-3pmzpc2p-requirement.txt (line 1))', '  Downloading https://www.piwheels.org/simple/numpy/numpy-1.16.4-cp37-cp37m-linux_armv7l.whl (7.4MB)']
[pipenv.exceptions.InstallError]: ['ERROR: 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.', '    numpy==1.16.4 from https://www.piwheels.org/simple/numpy/numpy-1.16.4-cp37-cp37m-linux_armv7l.whl#sha256=2010ae83ce5936239f400c953fbd4fed34ca9af2345426f3c64d5a4ec16009dc (from -r /tmp/pipenv-t5vvgr38-requirements/pipenv-3pmzpc2p-requirement.txt (line 1)):', '        Expected sha256 0778076e764e146d3078b17c24c4d89e0ecd4ac5401beff8e1c87879043a0633', '        Expected     or 141c7102f20abe6cf0d54c4ced8d565b86df4d3077ba2343b61a6db996cefec7', '        Expected     or 14270a1ee8917d11e7753fb54fc7ffd1934f4d529235beec0b275e2ccf00333b', '        Expected     or 27e11c7a8ec9d5838bc59f809bfa86efc8a4fd02e58960fa9c49d998e14332d5', '        Expected     or 2a04dda79606f3d2f760384c38ccd3d5b9bb79d4c8126b67aff5eb09a253763e', '        Expected     or 3c26010c1b51e1224a3ca6b8df807de6e95128b0908c7e34f190e7775455b0ca', '        Expected     or 52c40f1a4262c896420c6ea1c6fda62cf67070e3947e3307f5562bd783a90336', '        Expected     or 6e4f8d9e8aa79321657079b9ac03f3cf3fd067bf31c1cca4f56d49543f4356a5', '        Expected     or 7242be12a58fec245ee9734e625964b97cf7e3f2f7d016603f9e56660ce479c7', '        Expected     or 7dc253b542bfd4b4eb88d9dbae4ca079e7bf2e2afd819ee18891a43db66c60c7', '        Expected     or 94f5bd885f67bbb25c82d80184abbf7ce4f6c3c3a41fbaa4182f034bba803e69', '        Expected     or a89e188daa119ffa0d03ce5123dee3f8ffd5115c896c2a9d4f0dbb3d8b95bfa3', '        Expected     or ad3399da9b0ca36e2f24de72f67ab2854a62e623274607e37e0ce5f5d5fa9166', '        Expected     or b0348be89275fd1d4c44ffa39530c41a21062f52299b1e3ee7d1c61f060044b8', '        Expected     or b5554368e4ede1856121b0dfa35ce71768102e4aa55e526cb8de7f374ff78722', '        Expected     or cbddc56b2502d3f87fda4f98d948eb5b11f36ff3902e17cb6cc44727f2200525', '        Expected     or d79f18f41751725c56eceab2a886f021d70fd70a6188fd386e29a045945ffc10', '        Expected     or dc2ca26a19ab32dc475dbad9dfe723d3a64c835f4c23f625c2b6566ca32b9f29', '        Expected     or dd9bcd4f294eb0633bb33d1a74febdd2b9018b8b8ed325f861fffcd2c7660bb8', '        Expected     or e8baab1bc7c9152715844f1faca6744f2416929de10d7639ed49555a85549f52', '        Expected     or ec31fe12668af687b99acf1567399632a7c47b0e17cfb9ae47c098644ef36797', '        Expected     or f12b4f7e2d8f9da3141564e6737d79016fe5336cc92de6814eba579744f65b0a', '        Expected     or f58ac38d5ca045a377b3b377c84df8175ab992c970a53332fa8ac2373df44ff7', '             Got        2010ae83ce5936239f400c953fbd4fed34ca9af2345426f3c64d5a4ec16009dc']
ERROR: ERROR: Package installation failed...

It looks like piwheels.org index is there, which is good. Why is this error happening and how do we resolve it?


Solution

  • I solved it by:

    1. Downgrading to Raspbian Stretch (instead of using Buster which is new as of 2019/06),
    2. First installing opencv-contrib-python 3.4.4.19, then opencv-python
    pipenv install opencv-contrib-python==3.4.4.19
    pipenv install opencv-python==3.4.4.19
    

    Raspbian Buster did not work because the wheels from piwheels.org are not ready yet; their builds are delayed and still catching up because of a multi-month technical snag they ran into, as can be verified on the package page where under "Successful Builds" column we find cp34m and cp35m, but no cp37m (Buster builds). Beyond that, I don't know why I still got the hash error in Sketch for the opencv-python build, requiring to first install opencv-contrib-python.

    Also, don't forget to install the library dependencies before you try to import cv2 and use it (source credit):

    $ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
    $ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
    $ sudo apt-get install libatlas-base-dev
    $ sudo apt-get install libjasper-dev