ubuntu18.04 安装opencv-python遇到的问题

  • 常规安装步骤
    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python

    通常会报错:

  •   Traceback (most recent call last):
        File "", line 1, in 
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 511, in 
          main()
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 289, in main
          cmake_source_dir=cmake_source_dir,
        File "/home/idriver/.local/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 629, in setup
          cmake_source_dir, skbuild_kw['cmake_install_dir'])
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 424, in _classify_installed_files_override
          raise Exception("Not found: '%s'" % relpath_re)
      Exception: Not found: 'python/cv2/gapi/.*\.py'
      
      ----------------------------------------
      Failed building wheel for opencv-python
    

    解决方法:

  • sudo apt-get install cmake

    仍然报错:

     Not searching for unused variables given on the command line.
        CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

    解决方法:

    sudo apt-get install ninja
    ln -s  /usr/bin/ninja  /usr/bin/ninja-build

    仍然报错:

      Traceback (most recent call last):
        File "", line 1, in 
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 511, in 
          main()
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 289, in main
          cmake_source_dir=cmake_source_dir,
        File "/home/idriver/.local/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 629, in setup
          cmake_source_dir, skbuild_kw['cmake_install_dir'])
        File "/tmp/pip-build-r06d1wnz/opencv-python/setup.py", line 424, in _classify_installed_files_override
          raise Exception("Not found: '%s'" % relpath_re)
      Exception: Not found: 'python/cv2/gapi/.*\.py'
      
      ----------------------------------------
      Failed building wheel for opencv-python
    

    解决方法:

    pip install --upgrade pip

    然后安装成功。

    Collecting opencv-python
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/87/7f/92d75cc58781877b6446c8d35a1b6bf11c914d6a39418819405b63531e4b/opencv_python-4.5.4.60-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.3 MB)
         |████████████████████████████████| 60.3 MB 2.0 MB/s 
    Requirement already satisfied: numpy>=1.13.3 in ./.local/lib/python3.6/site-packages (from opencv-python) (1.19.5)
    Installing collected packages: opencv-python
    Successfully installed opencv-python-4.5.4.60

你可能感兴趣的:(算法,python,opencv,计算机视觉)