opencv-python: 4.8.0.74: `Exception: Not found: 'python/cv2/py.typed'` when building a contrib wheel with CUDA

Expected behaviour

Build a python-3.11 contrib wheel

Actual behaviour

Creating the wheel failed with this error:

  Copying files from CMake output
  creating directory _skbuild/linux-x86_64-3.11/cmake-install/cv2
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/python-3/cv2.abi3.so -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/cv2.abi3.so
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/__init__.py -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/__init__.py
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/load_config_py2.py -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/load_config_py2.py
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/load_config_py3.py -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/load_config_py3.py
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/config.py -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/config.py
  copying _skbuild/linux-x86_64-3.11/cmake-install/python/cv2/config-3.py -> _skbuild/linux-x86_64-3.11/cmake-install/cv2/config-3.py
  Traceback (most recent call last):
    File "/home/alex/T7/src/opencv-python/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/home/alex/T7/src/opencv-python/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/alex/T7/src/opencv-python/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-mheswsk1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 230, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-mheswsk1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 215, in _build_with_temp_dir
      self.run_setup()
    File "/tmp/pip-build-env-mheswsk1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 268, in run_setup
      self).run_setup(setup_script=setup_script)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-mheswsk1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 158, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 532, in <module>
      main()
    File "setup.py", line 264, in main
      skbuild.setup(
    File "/tmp/pip-build-env-mheswsk1/overlay/lib/python3.11/site-packages/skbuild/setuptools_wrap.py", line 706, in setup
      _classify_installed_files(
    File "setup.py", line 445, in _classify_installed_files_override
      raise Exception("Not found: '%s'" % relpath_re)
  Exception: Not found: 'python/cv2/py.typed'
  error: subprocess-exited-with-error
  
  × Building wheel for opencv-contrib-python (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/alex/T7/src/opencv-python/venv/bin/python3.11 /home/alex/T7/src/opencv-python/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /tmp/tmpo050xxg7
  cwd: /home/alex/T7/src/opencv-python
  Building wheel for opencv-contrib-python (pyproject.toml) ... error
  ERROR: Failed building wheel for opencv-contrib-python
Failed to build opencv-contrib-python
ERROR: Failed to build one or more wheels

Steps to reproduce

git clone https://github.com/opencv/opencv-python.git
cd opencv-python
git checkout tags/74 -b 4.8.0.74
git submodule update --init --recursive
python3.11 -m venv venv
source venv/bin/activate
pip install -U pip wheel
export CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RELEASE -DWITH_CUDA=ON -DWITH_CUDNN=ON -DWITH_CUBLAS=ON -DWITH_TBB=ON -DOPENCV_DNN_CUDA=ON -DOPENCV_ENABLE_NONFREE=ON -DCUDA_ARCH_BIN=7.5 -DBUILD_EXAMPLES=OFF -DHAVE_opencv_python3=ON"
export ENABLE_CONTRIB=1
pip wheel . --verbose

The same scenario built fine with 4.7.0.72, I assume it is related to b534ea27a65acc766575bdface4abc984178eee8

  • Ubuntu 22.04
  • architecture amd64
  • opencv-python 4.8.0.74
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 22

Commits related to this issue

Most upvoted comments

Python type stubs are not generated by some reason. I reproduced the issue locally with python3.8. Looks like it’s somehow related to CUDA modules.

Apologies, I just realized that when I built my latest version I had

export ENABLE_ROLLING=1

and on the .74 version I manually altered the build file not to check for the missing files.

You can check the full command line in Build Summary for my latest OpenCV python CUDA wheel.

Removing

+
        [ r"python/cv2/py.typed" ] if sys.version_info >= (3, 6) else []

and

 if sys.version_info >= (3, 6):
        rearrange_cmake_output_data["cv2.typing"] = ["python/cv2" + r"/typing/.*\.py"]

from setup.py can compile a whl file with cudacodec. But frame_count from output video is negative. Related issue: https://github.com/opencv/opencv_contrib/issues/3556

Still has error while compiling, but still usable for final whl:

2023-08-30T01:26:13.0435435Z   /home/vsts/work/1/s/opencv-python/opencv/modules/python/src2/typing_stubs_generator.py:52: UserWarning: Typing stubs generation has failed.
2023-08-30T01:26:13.0435853Z   Traceback (most recent call last):
2023-08-30T01:26:13.0436237Z     File "/home/vsts/work/1/s/opencv-python/opencv/modules/python/src2/typing_stubs_generator.py", line 49, in wrapped_func
2023-08-30T01:26:13.0436492Z       ret_type = func(*args, **kwargs)
2023-08-30T01:26:13.0437015Z     File "/home/vsts/work/1/s/opencv-python/opencv/modules/python/src2/typing_stubs_generator.py", line 148, in _generate
2023-08-30T01:26:13.0437348Z       generate_typing_stubs(self.cv_root, output_path)
2023-08-30T01:26:13.0437771Z     File "/home/vsts/work/1/s/opencv-python/opencv/modules/python/src2/typing_stubs_generation/generation.py", line 86, in generate_typing_stubs
2023-08-30T01:26:13.0438098Z       root.resolve_type_nodes()
2023-08-30T01:26:13.0438518Z     File "/home/vsts/work/1/s/opencv-python/opencv/modules/python/src2/typing_stubs_generation/nodes/namespace_node.py", line 106, in resolve_type_nodes
2023-08-30T01:26:13.0438857Z       raise TypeResolutionError(
2023-08-30T01:26:13.0442380Z   typing_stubs_generation.nodes.type_node.TypeResolutionError: Failed to resolve "cv2" namespace against "None". Errors: ['Failed to resolve "cv2.cudacodec" namespace against "cv2". Errors: [\'Failed to resolve "cv2.cudacodec.createVideoWriter" function against "cv2". Errors: [0]: Failed to resolve "stream" argument: Failed to resolve "Stream" exposed as "Stream", [1]: Failed to resolve "stream" argument: Failed to resolve "Stream" exposed as "Stream"\', \'Failed to resolve "cv2.cudacodec.EncodeQp" class against "cv2". Errors: [\\\'Failed to resolve "qpInterP" property\\\', \\\'Failed to resolve "qpInterB" property\\\', \\\'Failed to resolve "qpIntra" property\\\']\', \'Failed to resolve "cv2.cudacodec.EncoderParams" class against "cv2". Errors: [\\\'Failed to resolve "targetQuality" property\\\']\', \'Failed to resolve "cv2.cudacodec.VideoReader" class against "cv2". Errors: [\\\'Failed to resolve "cv2.cudacodec.VideoReader.nextFrame" function against "cv2". Errors: [0]: Failed to resolve "frame" argument: Failed to resolve one of "GpuMat | None" items. Errors: [\\\\\\\'Failed to resolve "GpuMat" exposed as "GpuMat"\\\\\\\'], [1]: Failed to resolve "stream" argument: Failed to resolve "Stream" exposed as "Stream", [2]: Failed to resolve return type: Failed to resolve one of "tuple[bool, GpuMat]" items. Errors: [\\\\\\\'Failed to resolve "GpuMat" exposed as "GpuMat"\\\\\\\']\\\', \\\'Failed to resolve "cv2.cudacodec.VideoReader.grab" function against "cv2". Errors: [0]: Failed to resolve "stream" argument: Failed to resolve "Stream" exposed as "Stream"\\\', \\\'Failed to resolve "cv2.cudacodec.VideoReader.retrieve" function against "cv2". Errors: [0]: Failed to resolve "frame" argument: Failed to resolve one of "GpuMat | None" items. Errors: [\\\\\\\'Failed to resolve "GpuMat" exposed as "GpuMat"\\\\\\\'], [1]: Failed to resolve return type: Failed to resolve one of "tuple[bool, GpuMat]" items. Errors: [\\\\\\\'Failed to resolve "GpuMat" exposed as "GpuMat"\\\\\\\']\\\']\']']

Indeed, disabling cudacodec and cudaoptflow got the wheel built. Since it’s missing FarnebackOpticalFlow I need, for now I just removed these lines from setup.py:

diff --git a/setup.py b/setup.py
index b17c11e..47647e6 100644
--- a/setup.py
+++ b/setup.py
@@ -130,8 +130,6 @@ def main():
         [
             r"python/cv2/.*config.*.py"
         ]
-        +
-        [ r"python/cv2/py.typed" ] if sys.version_info >= (3, 6) else []
         ,
         "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
             ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"