Cannot pip install OpenCV 4.5.4.* on MacOS Mojave

Environment

  • MacOS Mojave
  • Python 3.9.13
  • OpenCV 4.5.4*
  • installer

Command

$ pip install opencv-python==4.5.4.56

Message

        File "/private/var/folders/64/kzf5_d7n3wlcl3r3yzp770g00000gn/T/pip-build-env-jcn8ws74/overlay/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 676, in setup
          _classify_installed_files(
        File "<string>", line 381, in _classify_installed_files_override
      FileNotFoundError: [Errno 2] No such file or directory: 'scripts/__init__.py'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects

I tried to install 4.5.4.58, 4.5.4.60, and 4.6.0.66, but failed with the same error.

Any help will be appreciated!

you don’t have to build.

either upgrade your OS, or use an earlier version of opencv, because there are packages that should work for your OS (10.14):

opencv v4.5.1: opencv-python · PyPI

that’s the latest opencv with packages that don’t require 10.15 or later.

if you want to build OpenCV, you build OpenCV. that contains python bindings. the opencv-python build stuff is for the self-contained package, which you don’t need. just build opencv itself.

I had exactly the same problem. Don’t know if it will apply to your case, but I tried installing open-cv-headless with conda and it worked for me !

conda install -c fastai opencv-python-headless