opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.48k stars 842 forks source link

pip installation failed in raspberry pi #786

Closed tedchou12 closed 1 year ago

tedchou12 commented 1 year ago

Expected behaviour

Write here how did you expect the library to function. able to install

Actual behaviour

pi@raspberrypi:~/opencv/python/opencv-python-4.x $ pip3 install opencv-python
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-python
  Using cached opencv-python-4.7.0.68.tar.gz (91.1 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [81 lines of output]
      Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple, https://www.piwheels.org/simple
      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.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"' don't match your environment
      Ignoring numpy: markers 'python_version >= "3.10" and platform_system == "Darwin"' don't match your environment
      Collecting setuptools==59.2.0
        Using cached https://www.piwheels.org/simple/setuptools/setuptools-59.2.0-py3-none-any.whl (952 kB)
      Collecting wheel==0.37.0
        Using cached https://www.piwheels.org/simple/wheel/wheel-0.37.0-py2.py3-none-any.whl (35 kB)
      Collecting cmake>=3.1
        Using cached cmake-3.25.0.tar.gz (33 kB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Collecting pip
        Using cached pip-22.3.1-py3-none-any.whl (2.1 MB)
      Collecting scikit-build>=0.13.2
        Using cached https://www.piwheels.org/simple/scikit-build/scikit_build-0.16.6-py3-none-any.whl (79 kB)
      Collecting numpy==1.17.3
        Using cached numpy-1.17.3-cp38-cp38-linux_armv7l.whl
      Collecting packaging
        Using cached https://www.piwheels.org/simple/packaging/packaging-23.0-py3-none-any.whl (42 kB)
      Collecting distro
        Using cached https://www.piwheels.org/simple/distro/distro-1.8.0-py3-none-any.whl (20 kB)
      Building wheels for collected packages: cmake
        Building wheel for cmake (pyproject.toml): started
        Building wheel for cmake (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

        × Building wheel for cmake (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [37 lines of output]
            Traceback (most recent call last):
              File "/usr/local/bin/cmake", line 5, in <module>
                from cmake import cmake
            ModuleNotFoundError: No module named 'cmake'
            Traceback (most recent call last):
              File "/tmp/pip-build-env-vm7ykws9/overlay/lib/python3.8/site-packages/skbuild/setuptools_wrap.py", line 621, in setup
                cmkr = cmaker.CMaker(cmake_executable)
              File "/tmp/pip-build-env-vm7ykws9/overlay/lib/python3.8/site-packages/skbuild/cmaker.py", line 151, in __init__
                self.cmake_version = get_cmake_version(self.cmake_executable)
              File "/tmp/pip-build-env-vm7ykws9/overlay/lib/python3.8/site-packages/skbuild/cmaker.py", line 106, in get_cmake_version
                raise SKBuildError(

                =============================DEBUG ASSISTANCE=============================
                If you are seeing a compilation error please try the following steps to
                successfully install cmake:
                1) Upgrade to the latest pip and try again. This will fix errors for most
                   users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
                2) If on Linux, with glibc < 2.12, you can set PIP_ONLY_BINARY=cmake in
                   order to retrieve the last manylinux1 compatible wheel.
                3) If on Linux, with glibc < 2.12, you can cap "cmake<3.23" in your
                   requirements in order to retrieve the last manylinux1 compatible wheel.
                4) Open an issue with the debug information that follows at
                   https://github.com/scikit-build/cmake-python-distributions/issues

                Python: 3.8.16
                platform: Linux-4.19.66-v7+-armv7l-with-glibc2.17
                glibc: glibc 2.24
                machine: armv7l
                bits: 32
                pip: n/a
                setuptools: 66.1.1
                scikit-build: 0.16.6
                PEP517_BUILD_BACKEND=setuptools.build_meta
                =============================DEBUG ASSISTANCE=============================

            Problem with the CMake installation, aborting build. CMake executable is /usr/local/bin/cmake
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for cmake
      Failed to build cmake
      ERROR: Could not build wheels for cmake, which is required to install pyproject.toml-based projects
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies 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.
pi@raspberrypi:~/opencv/python/opencv-python-4.x $ 

Write here what went wrong.

Steps to reproduce

Issue submission checklist
tedchou12 commented 1 year ago

PIP I didn't solve.

But I found out a way to download and compile. There was a ram not enough error with self compiling. This was solved by increasing the swap. The Raspberry PI 3B+ ram is 1GB, not enough for compiling.

sudo dphys-swapfile swapoff
sudo vim /etc/dphys-swapfile # swap 100MB to 2GB

then compile again:

sudo git clone https://github.com/opencv/opencv.git
sudo git clone https://github.com/opencv/opencv_contrib.git

cd opencv
sudo mkdir build
cd build
sudo cmake

sudo make -j2
sudo make install

It takes quite a while. Must be patient.

tedchou12 commented 1 year ago

build.003.zip build.002.zip build.001.zip build.000.zip

tedchou12 commented 1 year ago

Build directory, if the hardware is not too different, may be it might work for others.

  1. Expand the build
  2. make install
tedchou12 commented 1 year ago

references: https://www.geeksforgeeks.org/how-to-capture-a-image-from-webcam-in-python/ https://stackoverflow.com/questions/38613316/how-to-upgrade-pip3 https://magazine.techacademy.jp/magazine/51404 note: This error originates from a subprocess, and is likely not a problem with pip. raspberry pi https://www.partitionwizard.jp/partitionmanager/python-setup-py-egg-info-failed-with-error-code-1.html https://stackoverflow.com/questions/63448467/installing-opencv-fails-because-it-cannot-find-skbuild https://qiita.com/fiftystorm36/items/1a285b5fbf99f8ac82eb https://elsammit-beginnerblg.hatenablog.com/entry/2020/09/17/075234 https://stackoverflow.com/questions/70588185/warning-the-script-pip3-8-is-installed-in-usr-local-bin-which-is-not-on-path https://qiita.com/wk_/items/8db529a6b24a955888db https://learnopencv.com/install-opencv-4-on-raspberry-pi/ https://docs.opencv.org/4.x/d2/de6/tutorial_py_setup_in_ubuntu.html https://salt22g.hatenablog.jp/entry/2020/05/08/191316 https://blog.ligun.net/2013/08/raspberry_pi_opencv/ https://stackoverflow.com/questions/48146273/install-opencv-on-raspberry-pi-raspbian https://github.com/opencv/opencv_contrib/issues/1979 https://elda27.hatenablog.com/entry/2020/01/29/225534 https://linuxhint.com/disable-gui-raspberry-pi/ https://forum.opencv.org/t/why-does-raspberry-pi-freeze-at-99-build/2207 https://askubuntu.com/questions/927854/how-do-i-increase-the-size-of-swapfile-without-removing-it-in-the-terminal https://pimylifeup.com/raspberry-pi-swap-file/

https://www.miki-ie.com/raspberry-pi/raspberry-pi-3-b-opencv-3-4-6-cv2/

cmake -D CMAKE_BUILD_TYPE=RELEASE     -D CMAKE_INSTALL_PREFIX=/usr/local     -D ENABLE_NEON=ON     -D ENABLE_VFPV3=ON     -D BUILD_TESTS=OFF     -D WITH_TBB=OFF     -D INSTALL_PYTHON_EXAMPLES=OFF     -D BUILD_EXAMPLES=OFF ..
Petros626 commented 1 year ago

Until now the installation from source like you did worked for me and takes a long time for sure, BUT I wasn't able to really use OpenCV (tab completion functions). My IDE and OS showed me both, that the import is possible, but when I ran code it's without a behaviour.