Failed to Build Wheel For Opencv
Asked Answered
B

3

5

I upgraded wheel, pip, and setuptools all to the latest version, with the following command.

pip3.9 install --upgrade pip setuptools wheel

When I try to install opencv pip3.9 install opencv-python, It gives an error. I tried to install an older version, got the same error (4.5.5.62). Here is the error I got, please have a look, thank you!

Python Version: 3.9 (opencv-python worked when it was 3.8)

Application: PyCharm

Traceback (most recent call last):
        File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/private/var/folders/0v/j0nhw8p50yd3_w61mysphgjc0000gn/T/pip-build-env-rp7pv38q/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 244, in build_wheel
          return self._build_with_temp_dir(['bdist_wheel'], '.whl',
        File "/private/var/folders/0v/j0nhw8p50yd3_w61mysphgjc0000gn/T/pip-build-env-rp7pv38q/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 229, in _build_with_temp_dir
          self.run_setup()
        File "/private/var/folders/0v/j0nhw8p50yd3_w61mysphgjc0000gn/T/pip-build-env-rp7pv38q/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 281, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/private/var/folders/0v/j0nhw8p50yd3_w61mysphgjc0000gn/T/pip-build-env-rp7pv38q/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 174, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 502, in <module>
          main()
        File "setup.py", line 239, in main
          skbuild.setup(
        File "/private/var/folders/0v/j0nhw8p50yd3_w61mysphgjc0000gn/T/pip-build-env-rp7pv38q/overlay/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 676, in setup
          _classify_installed_files(
        File "setup.py", line 442, in _classify_installed_files_override
          return (cls.wraps._classify_installed_files)(
      TypeError: _classify_installed_files() got an unexpected keyword argument 'cmake_install_dir'
      [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
Bushwhacker answered 14/4, 2022 at 10:47 Comment(5)
github.com/opencv/opencv-python/issues/648Jonquil
Ok, I saw it, but should not this be fixed already ass the issue is closed? If so, why am I still getting errors?Bushwhacker
As far as I can see, your apparently have a version of scikit-build installed that is incompatible with the current release of opencv-python. Check out the latest state of the opencv-python repository with git and then install from source using pip3 install ., that should work.Lianne
Yes that worked, I guess the issue is not fixed although it is closed.Bushwhacker
@Bushwhacker Developers often mark an issue closed when it hits the master branch, but before that has been wrapped up into a public package. I agree it's confusing.Succeed
S
6

I had this issue as well. The fix for this issue hasn't been formally released through pip, so running pip3 install git+https://github.com/opencv/opencv-python will resolve the problem.

I know this has been technically resolved per the comment from mara004, but it is possible that some readers have never had to install a pip library directly from a Git repository before.

Singlehanded answered 26/4, 2022 at 18:14 Comment(2)
This is excellent and the only thing that worked for me on Mojave. I didn't know about this method of installing directly from a git repo so thank you for that.Pallua
this didnt work for meClishmaclaver
M
0

By inspect the source of the function cls.wraps._classify_installed_files.

print(inspect.getsource(cls.wraps._classify_installed_files))

I found the reason is there is no parameter named cmake_install_dir but _cmake_install_dir in function definition.

def _classify_installed_files(
    install_paths,
    package_data,
    package_prefixes,
    py_modules,
    new_py_modules,
    scripts,
    new_scripts,
    data_files,
    cmake_source_dir,
    _cmake_install_dir,
):
    assert not os.path.isabs(cmake_source_dir)
    assert cmake_source_dir != "."

    install_root = os.path.join(os.getcwd(), CMAKE_INSTALL_DIR())
    ......

so I changed the named parameter cmake_install_dir to _cmake_install_dir. then passed!

return (cls.wraps._classify_installed_files)(
            final_install_paths,
            package_data,
            package_prefixes,
            py_modules,
            new_py_modules,
            scripts,
            new_scripts,
            data_files,
            # To get around a check that prepends source dir to paths and breaks package detection code.
            cmake_source_dir="",
            _cmake_install_dir=cmake_install_reldir,
        )
Macroscopic answered 16/9, 2022 at 14:40 Comment(1)
This was the fix added in opencv-python repositoryMcleod
B
0

Create and Activate the Conda Virtual Environment and try conda install -c conda-forge opencv.

Bologna answered 16/7, 2023 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.