当前位置:   article > 正文

解决docker安装opencv-python-headless或其他安装包Could not build 问题_scikit-build could not get a working generator for

scikit-build could not get a working generator for your system. aborting bui

问题描述:在通过Dockerfile生成python项目运行环境时出现以下标志性报错:

  1. scikit-build could not get a working generator for your system. Aborting build.
  2. Building Linux wheels for Python 3.6 requires a compiler (e.g gcc).
  3. But scikit-build does *NOT* know how to install it on ubuntu
  4. To build compliant wheels, consider using the manylinux system described in PEP-513.
  5. Get it with "dockcross/manylinux-x64" docker image:
  6. https://github.com/dockcross/dockcross#readme
  7. For more details, please refer to scikit-build documentation:
  8. http://scikit-build.readthedocs.io/en/latest/generators.html#linux
  9. ********************************************************************************
  10. ----------------------------------------
  11. ERROR: Failed building wheel for opencv-python-headless

常伴随有:

  1. Failed to build opencv-python-headless
  2. ERROR: Could not build wheels for opencv-python-headless, which is required to install pyproject.toml-based projects

网上诸多已有的方法包括安装Visual Studio,更改安装版本,更新pip或更新pip wheel。但是都不能解决我的问题,通过仔细对比成功build的包和错误的包我发现问题所在:

成功的包流程如下:

  1. Collecting future==0.18.2
  2. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829 kB)
  3. #注意这边的下载是tar.gz所以有后面的两个以setup.py为核心的preparing步骤,这是最主要区别!!!!
  4. Preparing metadata (setup.py): started
  5. Preparing metadata (setup.py): finished with status 'done'
  6. ...
  7. Building wheels for collected packages: tabulate, future, opencv-python-headless
  8. Building wheel for future (setup.py): started
  9. Building wheel for future (setup.py): finished with status 'done'
  10. Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=c2232aeae9d0ed05abc2d50855ca7606800d73eb495ba80caf2cfbde9cb96f89
  11. Stored in directory: /home/user/.cache/pip/wheels/f3/f6/70/8b2bba44d8bf6ee5b7eac561416d9ef5c28dd2320490fc0f1f

错误的包流程如下:

  1. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/10/44/501dfcb9547deca7ab237e801ae80b2bbdbbffdc195cfe8aad8c0982b360/opencv-python-headless-4.7.0.68.tar.gz (91.1 MB)
  2. Installing build dependencies: started
  3. Installing build dependencies: finished with status 'done'
  4. Getting requirements to build wheel: started
  5. Getting requirements to build wheel: finished with status 'done'
  6. Preparing metadata (pyproject.toml): started
  7. Preparing metadata (pyproject.toml): finished with status 'done'
  8. #这是以pyproject.toml为主的preparing步骤
  9. ...
  10. Building wheel for opencv-python-headless (pyproject.toml): started
  11. Building wheel for opencv-python-headless (pyproject.toml): finished with status 'error'
  12. ERROR: Command errored out with exit status 1:

出于各种原因(python版本,conda环境等)docker中的pyproject.toml可能并不可用,导致最后的build失败

解决思路:既然tar.gz包的pyproject.toml不可用,那么我们就用whl类型文件完成安装不就好了吗?

PyPI · The Python Package Index上找到你需要的包复制下载链接后(以我的opencv链接为例)

https://files.pythonhosted.org/packages/7e/05/a3c67e6a2f6ae471941dbe556f3cd7b605adfb3eb7272bf4cbf89eacb97e/opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

在Dockerfile文件合适的位置中加入(一般在配置conda环境,或运行pip下载的地方)

  1. RUN wget https://files.pythonhosted.org/packages/7e/05/a3c67e6a2f6ae471941dbe556f3cd7b605adfb3eb7272bf4cbf89eacb97e/opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl \
  2. && pip install opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

即先下载whl包,然后直接pip离线安装

结果如下:

  1. Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
  2. Processing ./opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  3. Requirement already satisfied: numpy>=1.13.3 in /home/user/miniconda/envs/py36/lib/python3.6/site-packages (from opencv-python-headless==4.5.5.62) (1.19.2)
  4. Installing collected packages: opencv-python-headless
  5. Successfully installed opencv-python-headless-4.5.5.62
  6. ...
  7. Requirement already satisfied: opencv-python-headless in /home/user/miniconda/envs/py36/lib/python3.6/site-packages (from imgaug==0.3.0->-r requirements.txt (line 14)) (4.5.5.62)
  8. #环境检测到已有opencv则不再以默认的pyproject.toml方式安装
  9. ...
  10. Successfully installed Cython-0.29.14 PyWavelets-1.1.1 Shapely-1.8.5.post1 attrs-22.2.0 boto3-1.10.35 botocore-1.13.50 cycler-0.11.0 docutils-0.15.2 future-0.18.2 hypothesis-4.50.7 imageio-2.9.0 imgaug-0.3.0 jmespath-0.10.0 joblib-1.1.1 kiwisolver-1.3.1 matplotlib-3.3.4 numpy-1.18.1 pandas-1.0.1 pillow-7.1.2 pydot-1.4.1 pyparsing-3.0.9 python-dateutil-2.8.2 s3transfer-0.2.1 scikit-image-0.17.2 scikit-learn-0.21.3 scipy-1.4.1 seaborn-0.10.0 tabulate-0.8.6 tifffile-2020.9.3 tqdm-4.46.0
  11. Removing intermediate container 10d726e6c360
  12. ---> 0357ee3491db
  13. Successfully built 0357ee3491db
  14. Successfully tagged vein:v1.0

至此镜像创建完成

以上是本人解决问题的成功方法,但由于个人才疏学浅,文章中可能有不严谨甚至错误的地方,恳请诸位读者批评指正,文章方法供大家参考

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/108042
推荐阅读
相关标签
  

闽ICP备14008679号