ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
Asked Answered
M

12

44

I was trying to install OpenCV4 in a docker on jetson nano. It has jetpack 4.4 s os. The docker was successfully created and Tensorflow is running but while installing OpenCV using pip it is showing CMake error.

root@5abf405fb92d:~# pip3 install opencv-python
Collecting opencv-python
  Downloading opencv-python-4.4.0.42.tar.gz (88.9 MB)
     |████████████████████████████████| 88.9 MB 2.5 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from opencv-python) (1.18.4)
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpqpzwrofy
       cwd: /tmp/pip-install-93nxibky/opencv-python
  Complete output (9 lines):
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 560, in setup
      cmkr = cmaker.CMaker(cmake_executable)
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/cmaker.py", line 95, in __init__
      self.cmake_version = get_cmake_version(self.cmake_executable)
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/cmaker.py", line 82, in get_cmake_version
      "Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable)
  Traceback (most recent call last):
  
  Problem with the CMake installation, aborting build. CMake executable is cmake
  ----------------------------------------
  ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
Midge answered 3/9, 2020 at 22:15 Comment(1)
might this help? #43452703Cloudless
H
92

I had the same problem and i did this,

pip install --upgrade pip setuptools wheel

then install opencv again,

pip install opencv-python

this worked for me

Hypotension answered 5/9, 2020 at 9:40 Comment(5)
this answer, should be placed above. at the top! Solves the problem instantly on Windows.Briant
ERROR: Could not install packages due to an EnvironmentErrorAccomplish
This error continues to popup on Mac Sierra even after following this.Glossology
Just thought id mention that the pip upgrade command did not work for me and uninstalled pip because I did not add the --user argument. My venv did not have pip anymore. I then brought pip back via python -m ensurepip. And then running the command again with python -m worked flawlessly: python -m pip install --upgrade pip setuptools wheelUngraceful
It doesn't work for me (Win 11, Python 3.6). However, pip install opencv-python==4.5.5.64 worked for me.Heiney
S
31

If after

pip install --upgrade pip setuptools wheel

you still have the same error,

You can try to specify the older version of OpenCV to install.

Ex.

pip3 install opencv-python==3.4.13.47
Seriema answered 6/6, 2021 at 1:28 Comment(3)
I can verify this. With Python 3.6: pip install opencv-python tried to install 4.7.0.68 but failed in the manner indicated above even after upgrading pip, setuptools and wheel. However, pip install opencv-python==4.5.5.64 worked. Exactly as indicated in this answer. It works right out of the box for Python >= 3.7 but I need to use 3.6 and opencv still supports it.Bunkmate
I too can verify that this works.Guru
Yep, pip install opencv-python==4.5.5.64 worked for me. Thanks!Heiney
M
4

Yes .. Finally found a work around. Follow this https://github.com/mdegans/nano_build_opencv and build from source and finally gets installed.

PS: It may take a bit long for building, for me it took 10 Hrs :P.

Happy Image-Processing..

Midge answered 28/9, 2020 at 12:41 Comment(1)
Hi, thanks for sharing. I am hitting the same error, the numpy with parameter --platform linux/arm/v7 on last night build which took 11 hours and it was still not finished.Silin
I
3

I had a similar problem and what solved it for me was not to use python:3-alpine but python:3.8-slim. E.g.:

FROM python:3.8-slim
WORKDIR /usr/src/app

RUN apt update
RUN apt -y install build-essential libwrap0-dev libssl-dev libc-ares-dev uuid-dev xsltproc
RUN apt-get update -qq \
    && apt-get install --no-install-recommends --yes \
        build-essential \
        gcc \
        python3-dev \
        mosquitto \
        mosquitto-clients


RUN pip3 install --upgrade pip setuptools wheel

RUN python3 -m pip install --no-cache-dir \
      numpy scipy matplotlib scikit-build opencv-contrib-python-headless \
      influxdb paho-mqtt configparser Pillow \
      qrcode

worked finally for me.

Ideograph answered 23/8, 2021 at 16:51 Comment(0)
D
2

try using this pip install opencv-python==4.5.3.56

Dissert answered 26/7, 2023 at 15:51 Comment(1)
Unless there's a reason this specific python version should be used, I don't see this value of keeping this answer when this other one exists: stackoverflow.com/a/67855136Arginine
C
1

I came across similiar situation
I had error

Failed to build opencv-python ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly WARNING: You are using pip version 19.2.3, however version 22.0.4 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

I ran in command prompt with admin privileges following
python -m pip install --upgrade pip
Now "pip install opencv-python" works

Chelseychelsie answered 7/5, 2022 at 14:33 Comment(0)
S
1

I had similar issue in installing OpenCV in Anaconda 3 using Python version 3.6.PIP was not able to build the wheel.

The following two commands solved my issue:

pip install --upgrade pip setuptools wheel

pip3 install opencv-python==4.7.0.68

Thanks

Stinson answered 30/7, 2023 at 8:40 Comment(1)
This is @willSapgreen's answer with a different version number for opencv-pythonButterfly
E
0

please check your python specifications:


  - opencv -> python[
version='
>=2.7,<2.8.0a0
>=3.5,<3.6.0a0
>=3.6,<3.7.0a0
>=3.7,<3.8.0a0']
Ecumenicalism answered 2/11, 2021 at 1:52 Comment(0)
R
0

I handled it by reinstalling python3 from scratch in my MacBook:

brew reinstall [email protected]

I also reinstalled numpy and matplotlib packages experimentally.

pip3 install numpy
pip3 install matplotlib 
pip3 install opencv-contrib-python

The versions:

macOS Mojave 10.14.5
Python 3.9.7
OpenCV 4.5.3

OpenCV's version is 4.5.3 by this way:

import cv2 
print(cv2.__version__)

But by "pip list", it shows "opencv-contrib-python 3.4.9.31".

Rhynd answered 17/11, 2021 at 13:18 Comment(0)
S
0

consider installing python3-dev or python3-devel using yum it worked for me with opencv-python-headless when it cant build wheel

Saberio answered 7/2 at 23:21 Comment(0)
C
0

pip3 install opencv-python==3.4.13.47

Worked for me with python version 3.7

Caftan answered 14/5 at 8:44 Comment(1)
The answer you have given has already been posted. Also please try to explain how your proposal relates to the issue at hand and what problem in particular it is trying to solve.Greybeard
P
-1

if you are trying to install opencv in your raspberrypi 3B, Use following steps:

  1. sudo raspi-config
  2. advanced -- expand filesystem
  3. reboot your pi

Open your raspi terminal and do following stuff:

  1. use command: sudo apt-get update
  2. use command: sudo apt-get upgrade
  3. check your python version and upgarde it to latest one
  4. install pip and upgrade pip
  5. use command: mkdir project
  6. use command: cd project
  7. create virtual environment
  8. activate virtual environment
  9. install dependencies ,can get dependencies from https://singleboardbytes.com/647/install-opencv-raspberry-pi-4.htm
  10. if error in installing libdhf5-dev
  11. use command: sudo apt-get install python3-h5py and reinstall libdhf5-dev
  12. use command: pip install scikit-build
  13. use command: pip install cython
  14. before installing opencv ,make sure you are in virtual environment or activate environment
  15. use command: pip install --no-cache-dir opencv-contrib-python==4.5.3.56
  16. Remember to use mentioned version...

Thank You...

Premium answered 17/4, 2022 at 9:53 Comment(2)
Please reformat your answer. It looks so bad to read.Respiratory
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewPianism

© 2022 - 2024 — McMap. All rights reserved.