gpt4 book ai didi

python - docker 无法构建 scipy

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:11 25 4
gpt4 key购买 nike

我正在尝试为我的 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 时遇到问题,因为它是作为要求的一部分安装的?

最佳答案

因为要构建 scipy wheel,你需要安装 numpy。但是,当 pip 尝试构建 scipy wheel 时,只有 numpy wheel 构建完成。

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

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

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

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

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

关于python - docker 无法构建 scipy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com