opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

Build from source python 3.12 fails

Open EnricoBeltramo opened this issue 1 year ago • 6 comments

Expected behaviour

I tried to build the tag 80 in python 3.12, but build fails

Write here how did you expect the library to function. correct build from source

Actual behaviour

Write here what went wrong. install of some dependencies (i.e. numpy) fail with this error: AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? the dependencies versions of numpy and setuptools are outdated and broken in python 3.12. Is it possible to use latest versions of those packages?

Steps to reproduce

  • example code: build from source as tutorial in main page
  • operating system: Ubuntu 22.04
  • architecture (e.g. x86): x86
  • opencv-python version: 80
Issue submission checklist
  • [x] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • [x] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • [x] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • [x] I'm using the latest version of opencv-python

EnricoBeltramo avatar May 28 '24 22:05 EnricoBeltramo

https://stackoverflow.com/questions/77364550/attributeerror-module-pkgutil-has-no-attribute-impimporter-did-you-mean

asmorkalov avatar May 30 '24 10:05 asmorkalov

I already tried that and it didn't work.

EnricoBeltramo avatar May 31 '24 00:05 EnricoBeltramo

https://github.com/opencv/opencv-python/pull/992/

asmorkalov avatar Jun 03 '24 13:06 asmorkalov

I'm also getting the same error with the latest merged updates:

Processing /home/aurelien/Projects/GitHub/opencv-python
  Running command pip subprocess to install build dependencies
  Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.8" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
  Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment
  Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.9" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.10" and platform_system != "Darwin"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Darwin"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.11"' don't match your environment
  Collecting cmake>=3.1
    Using cached cmake-3.29.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.1 kB)
  Collecting numpy>=1.26.4
    Using cached numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
  Collecting pip
    Using cached pip-24.0-py3-none-any.whl.metadata (3.6 kB)
  Collecting scikit-build>=0.14.0
    Using cached scikit_build-0.17.6-py3-none-any.whl.metadata (14 kB)
  Collecting setuptools==59.2.0
    Using cached setuptools-59.2.0-py3-none-any.whl.metadata (5.0 kB)
  Collecting distro (from scikit-build>=0.14.0)
    Using cached distro-1.9.0-py3-none-any.whl.metadata (6.8 kB)
  Collecting packaging (from scikit-build>=0.14.0)
    Using cached packaging-24.1-py3-none-any.whl.metadata (3.2 kB)
  Collecting wheel>=0.32.0 (from scikit-build>=0.14.0)
    Using cached wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
  Using cached setuptools-59.2.0-py3-none-any.whl (952 kB)
  Using cached cmake-3.29.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.7 MB)
  Using cached numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.0 MB)
  Using cached pip-24.0-py3-none-any.whl (2.1 MB)
  Using cached scikit_build-0.17.6-py3-none-any.whl (84 kB)
  Using cached wheel-0.43.0-py3-none-any.whl (65 kB)
  Using cached distro-1.9.0-py3-none-any.whl (20 kB)
  Using cached packaging-24.1-py3-none-any.whl (53 kB)
  Installing collected packages: wheel, setuptools, pip, packaging, numpy, distro, cmake, scikit-build
  Successfully installed cmake-3.29.5 distro-1.9.0 numpy-1.26.4 packaging-24.1 pip-24.0 scikit-build-0.17.6 setuptools-59.2.0 wheel-0.43.0
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  Traceback (most recent call last):
    File "/home/aurelien/Projects/GitHub/opencv-python/.venv/lib64/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/home/aurelien/Projects/GitHub/opencv-python/.venv/lib64/python3.12/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/aurelien/Projects/GitHub/opencv-python/.venv/lib64/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 112, in get_requires_for_build_wheel
      backend = _build_backend()
                ^^^^^^^^^^^^^^^^
    File "/home/aurelien/Projects/GitHub/opencv-python/.venv/lib64/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
      obj = import_module(mod_path)
            ^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 995, in exec_module
    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
    File "/tmp/pip-build-env-who73wyv/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 16, in <module>
      import setuptools.version
    File "/tmp/pip-build-env-who73wyv/overlay/lib/python3.12/site-packages/setuptools/version.py", line 1, in <module>
      import pkg_resources
    File "/tmp/pip-build-env-who73wyv/overlay/lib/python3.12/site-packages/pkg_resources/__init__.py", line 2172, in <module>
      register_finder(pkgutil.ImpImporter, find_on_path)
                      ^^^^^^^^^^^^^^^^^^^
  AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel 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/aurelien/Projects/GitHub/opencv-python/.venv/bin/python /home/aurelien/Projects/GitHub/opencv-python/.venv/lib64/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py get_requires_for_build_wheel /tmp/tmp35dh4ua_
  cwd: /home/aurelien/Projects/GitHub/opencv-python
  Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel 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.

montmejat avatar Jun 12 '24 08:06 montmejat

I encountered the same problem while running pip wheel . --verbose |& tee install_opencv.log. It worked after removing the ==59.2.0" from the "setuptools==59.2.0" https://github.com/opencv/opencv-python/blob/4.x/pyproject.toml#L16.

zhanwenchen avatar Jun 12 '24 18:06 zhanwenchen

Thank you @zhanwenchen, I also encountered the same issue (even after following the StackOverflow answer above), and solved it the same way. I think the ==59.2.0 prevents pip from using the most up-to-date setuptools that has this API change addressed.

Is there a particular reason why there's such a strict requirement for setuptools? Can I make a PR to remove it (or change it to >=59.2.0)?

sibocw avatar Jun 19 '24 10:06 sibocw

FIxed in https://github.com/opencv/opencv-python/pull/1061

asmorkalov avatar Jan 16 '25 12:01 asmorkalov