【问题标题】:Unable to install sklearn when building docker image构建docker镜像时无法安装sklearn
【发布时间】:2020-09-22 01:58:45
【问题描述】:

当我在构建 docker 映像时尝试安装 sklearn (scikit-learn) 时,它失败了。

这些是 Dockerfile 的已处理行:

FROM amancevice/pandas:0.25.0-alpine

RUN apk update
RUN apk add build-base
RUN apk add gcc musl-dev libc-dev util-linux-dev linux-headers python3-dev postgresql-libs postgresql-dev git libffi-dev libmemcached-dev zlib-dev ca-certificates zlib-dev jpeg-dev freetype-dev libpng

RUN pip3 install --upgrade pip
RUN pip3 install scikit-learn

一切都很顺利,直到最后一行。在那里,它首先需要永远,然后发生错误。这是日志:

Step 6/13 : RUN pip3 install scikit-learn
 ---> Running in 154f28d1d6db
Collecting scikit-learn
  Downloading scikit-learn-0.23.1.tar.gz (7.2 MB)
  Installing build dependencies: started
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.7 /usr/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-wy0vmutb/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'Cython>=0.28.5' 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation == '"'"'CPython'"'"'' 'numpy==1.14.0; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation != '"'"'CPython'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' and platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1'
       cwd: None
  Complete output (173 lines):
  Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation == "CPython"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation != "CPython"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment

这只是一些避免错误It looks like your post is mostly code; please add some more details.的文字。

  Collecting setuptools
    Downloading setuptools-47.1.1-py3-none-any.whl (583 kB)
  Collecting wheel
    Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
  Collecting Cython>=0.28.5
    Downloading Cython-0.29.19-py2.py3-none-any.whl (971 kB)
  Collecting numpy==1.14.5
    Downloading numpy-1.14.5.zip (4.9 MB)
  Collecting scipy>=0.19.1
    Downloading scipy-1.4.1.tar.gz (24.6 MB)
    Installing build dependencies: started
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: still running...
    Installing build dependencies: finished with status 'done'
    Getting requirements to build wheel: started
    Getting requirements to build wheel: finished with status 'done'
      Preparing wheel metadata: started
      Preparing wheel metadata: finished with status 'error'
      ERROR: Command errored out with exit status 1:
       command: /usr/bin/python3.7 /usr/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpam7hu__p
           cwd: /tmp/pip-install-r5ojdgp_/scipy
      Complete output (137 lines):
      lapack_opt_info:
      lapack_mkl_info:
      customize UnixCCompiler
        libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/']
        NOT AVAILABLE

      openblas_lapack_info:
      customize UnixCCompiler
      customize UnixCCompiler
        libraries openblas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/']
        NOT AVAILABLE

      openblas_clapack_info:
      customize UnixCCompiler
      customize UnixCCompiler
        libraries openblas,lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/']
        NOT AVAILABLE

      atlas_3_10_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/lib/
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/
      <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
        NOT AVAILABLE

      atlas_3_10_info:
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/lib/
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/
      <class 'numpy.distutils.system_info.atlas_3_10_info'>
        NOT AVAILABLE

      atlas_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/lib/
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/
      <class 'numpy.distutils.system_info.atlas_threads_info'>
        NOT AVAILABLE

      atlas_info:
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/lib/
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/
      <class 'numpy.distutils.system_info.atlas_info'>
        NOT AVAILABLE

      lapack_info:
      customize UnixCCompiler
        libraries lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/']
        NOT AVAILABLE

      lapack_src_info:
        NOT AVAILABLE

        NOT AVAILABLE

      setup.py:420: UserWarning: Unrecognized setuptools command ('dist_info --egg-base /tmp/pip-modern-metadata-lva1a_hp'), proceeding with generating Cython sources and expanding templates
        ' '.join(sys.argv[1:])))
      Running from scipy source directory.
      /tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/numpy/distutils/system_info.py:624: UserWarning:
          Atlas (http://math-atlas.sourceforge.net/) libraries not found.
          Directories to search for the libraries can be specified in the
          numpy/distutils/site.cfg file (section [atlas]) or by setting
          the ATLAS environment variable.
        self.calc_info()
      /tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/numpy/distutils/system_info.py:624: UserWarning:
          Lapack (http://www.netlib.org/lapack/) libraries not found.
          Directories to search for the libraries can be specified in the
          numpy/distutils/site.cfg file (section [lapack]) or by setting
          the LAPACK environment variable.
        self.calc_info()
      /tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/numpy/distutils/system_info.py:624: UserWarning:
          Lapack (http://www.netlib.org/lapack/) sources not found.
          Directories to search for the sources can be specified in the
          numpy/distutils/site.cfg file (section [lapack_src]) or by setting
          the LAPACK_SRC environment variable.
        self.calc_info()
      Traceback (most recent call last):
        File "/usr/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
          main()
        File "/usr/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 158, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 250, in run_setup
          self).run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 143, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 540, in <module>
          setup_package()
        File "setup.py", line 536, in setup_package
          setup(**metadata)
        File "/tmp/pip-build-env-ru46tr0i/overlay/lib/python3.7/site-packages/numpy/distutils/core.py", line 135, in setup
          config = configuration()
        File "setup.py", line 435, in configuration
          raise NotFoundError(msg)
      numpy.distutils.system_info.NotFoundError: No lapack/blas resources found.
      ----------------------------------------
  ERROR: Command errored out with exit status 1: /usr/bin/python3.7 /usr/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpam7hu__p Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.7 /usr/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-wy0vmutb/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'Cython>=0.28.5' 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation == '"'"'CPython'"'"'' 'numpy==1.14.0; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation != '"'"'CPython'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' and platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' Check the logs for full command output.
The command '/bin/sh -c pip3 install scikit-learn' returned a non-zero code: 1

【问题讨论】:

    标签: python docker scikit-learn dockerfile


    【解决方案1】:

    尝试降级您的 Python 版本,因为 Scikit Learn 还不支持 Python 3.9。

    【讨论】:

      【解决方案2】:

      我也有同样的问题。这个人用的是python 3.7,我用的是3.8 Python 版本应该不是这里的问题。

      尝试使用其他 Docker 镜像,例如 slim 镜像。

      FROM python:3.8-slim
      ...
      

      参考文献: Installing python numpy module inside python alpine docker

      【讨论】:

      • 我看不出这如何回答本页顶部的问题,但它应该。请edit根据How to Answer或删除答案。否则,它可能会被标记为“不是答案”并被删除。
      • 我尝试在上一个答案中添加评论。由于我的声誉低于50而失败。在这种情况下如何进行? PS.:我已经编辑了上面的答案并想出了一个解决方案。
      • 现在是一个显而易见的答案。做得好,谢谢。我对 docker 的了解并不多,但是“降级”的任何替代方法以及获取反馈都可以得到我的支持。现在(只要没有人反对)享受您的评论特权。但是,如果它再次被带走(肯定只是暂时的),请不要滥用回复帖子发表评论。需要 50 个代表来发表评论是有原因的。 meta.stackexchange.com/questions/214173/…
      猜你喜欢
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 2022-01-14
      • 2020-10-06
      • 2018-06-15
      相关资源
      最近更新 更多