opencv-python: Pip build fails: FileNotFoundError: [Errno 2] No such file or directory: 'scripts/__init__.py'

Reproduce:

  • pip install --upgrade pip setuptools wheel
  • CMAKE_ARGS="-DOPENCV_ENABLE_NONFREE=ON" pip install -v --no-binary=opencv-contrib-python opencv-contrib-python

Related commit: https://github.com/opencv/opencv-python/commit/6a1f61b8d7e413059dbf0b9e897579c8305c327f#diff-60f61ab7a8d1910d86d9fda2261620314edcae5894d5aaa236b821c7256badd7R389

Related PR: https://github.com/opencv/opencv-python/pull/563

Error:

Configuring Project
    Working directory:
      /tmp/pip-install-ais_cble/opencv-python_36817dc5e0834847b9d8f8f1dc7bd3c4/_skbuild/linux-x86_64-3.8/cmake-build
    Command:
      cmake /tmp/pip-install-ais_cble/opencv-python_36817dc5e0834847b9d8f8f1dc7bd3c4/opencv -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-install-ais_cble/opencv-python_36817dc5e0834847b9d8f8f1dc7bd3c4/_skbuild/linux-x86_64-3.8/cmake-install -DPYTHON_EXECUTABLE:FILEPATH=/home/elmeri/.venv/ml/bin/python3.8 -DPYTHON_VERSION_STRING:STRING=3.8.12 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPYTHON_LIBRARY:FILEPATH=/usr/lib/libpython3.8.so -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/skbuild/resources/cmake -DPYTHON3_EXECUTABLE=/home/elmeri/.venv/ml/bin/python3.8 -DPYTHON3_INCLUDE_DIR=/usr/include/python3.8 -DPYTHON3_LIBRARY=/usr/lib/libpython3.8.so -DBUILD_opencv_python3=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DOPENCV_PYTHON3_INSTALL_PATH=python -DINSTALL_CREATE_DISTRIB=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_freetype=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_DOCS=OFF -DOPENCV_ENABLE_NONFREE=ON -DCMAKE_BUILD_TYPE:STRING=Release

  Copying files from CMake output
  Traceback (most recent call last):
    File "/home/elmeri/.venv/ml/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
      main()
    File "/home/elmeri/.venv/ml/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/elmeri/.venv/ml/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 248, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 221, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
    File "/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 207, in _build_with_temp_dir
      self.run_setup()
    File "/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 258, in run_setup
      super(_BuildMetaLegacyBackend,
    File "/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 496, in <module>
      main()
    File "setup.py", line 248, in main
      skbuild.setup(
    File "/tmp/pip-build-env-bo2trral/overlay/lib/python3.8/site-packages/skbuild/setuptools_wrap.py", line 625, in setup
      _classify_installed_files(cmake_manifest, package_data, package_prefixes,
    File "setup.py", line 381, in _classify_installed_files_override
      with open('scripts/__init__.py', 'r') as custom_init:
  FileNotFoundError: [Errno 2] No such file or directory: 'scripts/__init__.py'
  Building wheel for opencv-python (pyproject.toml) ... error
  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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Installing the previous version succeeds using the following command:

pip install opencv-python==4.5.3.56

Workaround is to use an older release:

CMAKE_ARGS="-DOPENCV_ENABLE_NONFREE=ON" pip install -v --no-binary=opencv-contrib-python opencv-contrib-python==4.5.3.56

In my case, upgrading to the last pip version fixed the problem:

python3 -m pip install pip --upgrade

@asenyaev will this be fixed soon?

Upgrading to the latest pip version didn’t fix it for me, on 4.5.4.58

Failed on a Raspberry PI 4 with Debian buster Python: 3.7.3 pip: 21.3.1

Also the builds fails on piwheels: https://www.piwheels.org/project/opencv-python-headless/

Keeps the error

Copying files from CMake output
  Traceback (most recent call last):
    File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 262, in build_wheel
      metadata_directory)
    File "/tmp/pip-build-env-gnon1tj9/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 222, in build_wheel
      wheel_directory, config_settings)
    File "/tmp/pip-build-env-gnon1tj9/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 207, in _build_with_temp_dir
      self.run_setup()
    File "/tmp/pip-build-env-gnon1tj9/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 259, in run_setup
      self).run_setup(setup_script=setup_script)
    File "/tmp/pip-build-env-gnon1tj9/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 150, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 496, in <module>
      main()
    File "setup.py", line 289, in main
      cmake_source_dir=cmake_source_dir,
    File "/tmp/pip-build-env-gnon1tj9/overlay/lib/python3.7/site-packages/skbuild/setuptools_wrap.py", line 629, in setup
      cmake_source_dir, skbuild_kw['cmake_install_dir'])
    File "setup.py", line 381, in _classify_installed_files_override
      with open('scripts/__init__.py', 'r') as custom_init:
  FileNotFoundError: [Errno 2] No such file or directory: 'scripts/__init__.py'
  ----------------------------------------
  ERROR: Failed building wheel for opencv-python-headless

@tfuto, if you tried to just install opencv-python, I guess it means that you use a latest version (4.6.0.66). However, I couldn’t reproduce an issue with the latest version of opencv-python package on Ubuntu 22.04 LTS.

python3 -m pip install opencv-python
Collecting opencv-python
  Downloading opencv_python-4.6.0.66-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 MB 30.4 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.17.3 in /usr/lib/python3/dist-packages (from opencv-python) (1.21.5)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.6.0.66

Even the build from source using the command python3 -m pip install -v --no-binary=opencv-python-headless opencv-python-headless==4.6.0.66 finished successufully:

Collecting opencv-python-headless==4.6.0.66
  Downloading opencv-python-headless-4.6.0.66.tar.gz (90.3 MB)
  ...
  Building wheel for opencv-python-headless (pyproject.toml) ... done
  Created wheel for opencv-python-headless: filename=opencv_python_headless-4.6.0.66-cp310-cp310-linux_x86_64.whl size=28120290 sha256=0ac583a9298c42abaf58688ee9909678427e8298fd96691f03e8a776d42ecb95
  Stored in directory: /root/.cache/pip/wheels/4f/d2/a1/274a3a72cf197b06f6dd7a60c305fdfda1f3c49c9bc8d1d880
Successfully built opencv-python-headless
Installing collected packages: opencv-python-headless
Successfully installed opencv-python-headless-4.6.0.66

Fixed in 4.5.4.60. Tested with Ubuntu 18.04 and command:

python -m pip install -v --no-binary=opencv-python-headless opencv-python-headless==4.5.4.60

In my case, upgrading to the last pip version fixed the problem:

python3 -m pip install pip --upgrade

Faced this inside docker container on Nvidia Jetson nano, this fixed it for me too

@bartgrefte as soon #577 is merged I guess.

And for Pi look at: https://www.piwheels.org/project/opencv-python/ to see if there is a wheel version available.

The piwheels version availability chart for this project looks like a minefield.

… so that’s why “pip3 install opencv-python” failed.

FileNotFoundError: [Errno 2] No such file or directory: ‘scripts/init.py’ 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

Too bad it takes hours of compiling before this error appears. From which version is this fixed? (Thanks 😃 )

OS: Raspbian 10 Python: 3.7.3.

Same error for me 😦

  • Python 3.6.13 w/ pip 21.3.1
  • Ubuntu 18.04, ppc64le, GCC 7.5.0

@elmeriniemela thank you for your feedback!

At the moment, we hardly depends on files in opencv-python repository, especially on scripts folder, to build the proper package. I will remove this dependency to solve the issue.

I determined the issue that caused my build to fail:

The latest version of numpy is incompatible with Python 3.10.0. Link to numpy known issue.

This is extraordinarily confusing because the precompiled binary for numpy, installable via pip, successfully installs in Python 3 - but the build process for opencv-python requires rebuilding numpy from source, and that process fails under 3.10.0.

Installing Python 3.9.7, making that version global (via pyenv), and building opencv-python for Python 3.9.7 was successful.