赞
踩
问题描述:在通过Dockerfile生成python项目运行环境时出现以下标志性报错:
- scikit-build could not get a working generator for your system. Aborting build.
-
- Building Linux wheels for Python 3.6 requires a compiler (e.g gcc).
- But scikit-build does *NOT* know how to install it on ubuntu
-
- To build compliant wheels, consider using the manylinux system described in PEP-513.
- Get it with "dockcross/manylinux-x64" docker image:
-
- https://github.com/dockcross/dockcross#readme
-
- For more details, please refer to scikit-build documentation:
-
- http://scikit-build.readthedocs.io/en/latest/generators.html#linux
-
- ********************************************************************************
- ----------------------------------------
- ERROR: Failed building wheel for opencv-python-headless
常伴随有:
- Failed to build opencv-python-headless
- ERROR: Could not build wheels for opencv-python-headless, which is required to install pyproject.toml-based projects
网上诸多已有的方法包括安装Visual Studio,更改安装版本,更新pip或更新pip wheel。但是都不能解决我的问题,通过仔细对比成功build的包和错误的包我发现问题所在:
成功的包流程如下:
- Collecting future==0.18.2
- Downloading https://pypi.tuna.tsinghua.edu.cn/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829 kB)
- #注意这边的下载是tar.gz所以有后面的两个以setup.py为核心的preparing步骤,这是最主要区别!!!!
- Preparing metadata (setup.py): started
- Preparing metadata (setup.py): finished with status 'done'
- ...
- Building wheels for collected packages: tabulate, future, opencv-python-headless
- Building wheel for future (setup.py): started
- Building wheel for future (setup.py): finished with status 'done'
- Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=c2232aeae9d0ed05abc2d50855ca7606800d73eb495ba80caf2cfbde9cb96f89
- Stored in directory: /home/user/.cache/pip/wheels/f3/f6/70/8b2bba44d8bf6ee5b7eac561416d9ef5c28dd2320490fc0f1f
错误的包流程如下:
- Downloading https://pypi.tuna.tsinghua.edu.cn/packages/10/44/501dfcb9547deca7ab237e801ae80b2bbdbbffdc195cfe8aad8c0982b360/opencv-python-headless-4.7.0.68.tar.gz (91.1 MB)
- 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'
- #这是以pyproject.toml为主的preparing步骤
- ...
- Building wheel for opencv-python-headless (pyproject.toml): started
- Building wheel for opencv-python-headless (pyproject.toml): finished with status 'error'
- 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下载的地方)
- 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 \
- && pip install opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
即先下载whl包,然后直接pip离线安装
结果如下:
- Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
- Processing ./opencv_python_headless-4.5.5.62-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- 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)
- Installing collected packages: opencv-python-headless
- Successfully installed opencv-python-headless-4.5.5.62
- ...
- 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)
- #环境检测到已有opencv则不再以默认的pyproject.toml方式安装
- ...
- 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
- Removing intermediate container 10d726e6c360
- ---> 0357ee3491db
- Successfully built 0357ee3491db
- Successfully tagged vein:v1.0
至此镜像创建完成
以上是本人解决问题的成功方法,但由于个人才疏学浅,文章中可能有不严谨甚至错误的地方,恳请诸位读者批评指正,文章方法供大家参考
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。