代码之家  ›  专栏  ›  技术社区  ›  Luca

Docker不能制造scipy

  •  2
  • Luca  · 技术社区  · 6 年前

    我正在尝试为我的Python应用程序创建Docker容器(这是我第一次尝试使用Docker)。我查看了在线教程并创建了一个dockerfile,如下所示:

    FROM python:3.6-alpine
    COPY . /app
    WORKDIR /app
    
    RUN apk --update add --no-cache \ 
        lapack-dev \ 
        gcc \
        freetype-dev
    
    # Install dependencies
    RUN apk add --no-cache --virtual .build-deps \
        gfortran \
        musl-dev \
        g++
    
    RUN pip3 install -r requirements.txt
    
    RUN python3 setup.py install
    
    RUN apk del .build-deps
    
    ENTRYPOINT python3 testapp.py
    

    我的项目要求是:

    numpy==1.13.3
    Cython==0.28.2
    nibabel==2.2.1
    scipy==1.0.0
    

    我将Docker文件构建为: docker build -t myimg .

    因此,docker文件会继续,但scipy无法生成,并出现以下错误:

    Collecting numpy==1.13.3 (from -r requirements.txt (line 1))
      Downloading https://files.pythonhosted.org/packages/bf/2d/005e45738ab07a26e621c9c12dc97381f372e06678adf7dc3356a69b5960/numpy-1.13.3.zip (5.0MB)
    Collecting Cython==0.28.2 (from -r requirements.txt (line 2))
      Downloading https://files.pythonhosted.org/packages/79/9d/dea8c5181cdb77d32e20a44dd5346b0e4bac23c4858f2f66ad64bbcf4de8/Cython-0.28.2.tar.gz (1.9MB)
    Collecting nibabel==2.2.1 (from -r requirements.txt (line 3))
      Downloading https://files.pythonhosted.org/packages/d7/de/1d96fd0b118c9047bf35f02090db8ef8fd3927dfce635f09a6f7d5b572e6/nibabel-2.2.1.zip (4.2MB)
    Collecting scipy==1.0.0 (from -r requirements.txt (line 4))
      Downloading https://files.pythonhosted.org/packages/d0/73/76fc6ea21818eed0de8dd38e1e9586725578864169a2b31acdeffb9131c8/scipy-1.0.0.tar.gz (15.2MB)
    Collecting six>=1.3 (from nibabel==2.2.1->-r requirements.txt (line 3))
      Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
    Building wheels for collected packages: numpy, Cython, nibabel, scipy
      Running setup.py bdist_wheel for numpy: started
      Running setup.py bdist_wheel for numpy: still running...
      Running setup.py bdist_wheel for numpy: still running...
      Running setup.py bdist_wheel for numpy: still running...
      Running setup.py bdist_wheel for numpy: finished with status 'done'
      Stored in directory: /root/.cache/pip/wheels/b6/10/65/189b772e73b4505109d5a1e6671b07e65797023718777295e0
      Running setup.py bdist_wheel for Cython: started
      Running setup.py bdist_wheel for Cython: still running...
      Running setup.py bdist_wheel for Cython: still running...
      Running setup.py bdist_wheel for Cython: still running...
      Running setup.py bdist_wheel for Cython: finished with status 'done'
      Stored in directory: /root/.cache/pip/wheels/6f/24/5d/def09ad0aed8ba26186f2a38070906f70ab4b2287bf64d4414
      Running setup.py bdist_wheel for nibabel: started
      Running setup.py bdist_wheel for nibabel: finished with status 'done'
      Stored in directory: /root/.cache/pip/wheels/46/50/8d/bcb0b8f7c030da5bac1752fbe9cc375cbf5725fa93ba79ad84
      Running setup.py bdist_wheel for scipy: started
      Running setup.py bdist_wheel for scipy: finished with status 'error'
      Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-boosbyfg/scipy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-cczhwdqj --python-tag cp36:
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-install-boosbyfg/scipy/setup.py", line 418, in <module>
          setup_package()
        File "/tmp/pip-install-boosbyfg/scipy/setup.py", line 398, in setup_package
          from numpy.distutils.core import setup
      ModuleNotFoundError: No module named 'numpy'
    

    不知道为什么在作为需求的一部分安装时发现numpy有问题?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jay    6 年前

    因为要制造scpy车轮,你需要安装numpy。然而,只有麻木的车轮建设完成时,皮普试图建立scipy车轮。

    您必须首先安装依赖项。有多种方法可以做到这一点。

    1)使用下面的shell脚本,复制并运行它,而不是运行pip install-r requirements.txt:

    #!/bin/sh
    while read module; do
      pip install $module
    done < requirements.txt
    

    2)在单独的运行命令中安装scipy。

    3)APK添加py numpy@community,如中所述 this answer .