docker 无法构建python映像-pip安装要求失败

ivqmmu1c  于 2022-12-11  发布在  Docker
关注(0)|答案(1)|浏览(287)

Dockerfile中使用以下代码:

FROM python:3.8-alpine

WORKDIR /app

COPY requirements.txt .

RUN python3 -m pip install --upgrade pip

RUN pip3 install -r requirements.txt

RUN python3 -m spacy download en_core_web_sm

EXPOSE 80

CMD [ "python3", "main.py" ]

以及requirements.txt中的以下内容:

Flask==2.0.2
openai==0.13.0
spacy==3.2.1
stripe==2.65.0

图像构建在RUN pip3 install -r requirements.txt失败,日志如下。我注意到在尝试构建轮子时有几行声明error: command 'gcc' failed: No such file or directory

> [5/6] RUN pip3 install -r requirements.txt:                                                                                                                           
#9 4.488 Collecting Flask==2.0.2
#9 5.404   Downloading Flask-2.0.2-py3-none-any.whl (95 kB)
#9 5.813      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/95.2 KB 379.1 kB/s eta 0:00:00
#9 6.278 Collecting openai==0.13.0
#9 6.419   Downloading openai-0.13.0.tar.gz (37 kB)
#9 6.614   Preparing metadata (setup.py): started
#9 8.361   Preparing metadata (setup.py): finished with status 'done'
#9 9.383 Collecting spacy==3.2.1
#9 9.533   Downloading spacy-3.2.1.tar.gz (1.1 MB)
#9 15.19      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 188.2 kB/s eta 0:00:00
#9 18.18   Installing build dependencies: started
#9 140.2   Installing build dependencies: still running...
#9 160.1   Installing build dependencies: finished with status 'error'
#9 160.2   error: subprocess-exited-with-error
#9 160.2   
#9 160.2   × pip subprocess to install build dependencies did not run successfully.
#9 160.2   │ exit code: 1
#9 160.2   ╰─> [98 lines of output]
#9 160.2       Collecting setuptools
#9 160.2         Downloading setuptools-60.6.0-py3-none-any.whl (953 kB)
#9 160.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 953.8/953.8 KB 748.5 kB/s eta 0:00:00
#9 160.2       Collecting cython<3.0,>=0.25
#9 160.2         Downloading Cython-0.29.27-cp38-cp38-musllinux_1_1_x86_64.whl (2.1 MB)
#9 160.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 356.0 kB/s eta 0:00:00
#9 160.2       Collecting cymem<2.1.0,>=2.0.2
#9 160.2         Downloading cymem-2.0.6.tar.gz (8.2 kB)
#9 160.2         Installing build dependencies: started
#9 160.2         Installing build dependencies: finished with status 'done'
#9 160.2         Getting requirements to build wheel: started
#9 160.2         Getting requirements to build wheel: finished with status 'done'
#9 160.2         Installing backend dependencies: started
#9 160.2         Installing backend dependencies: finished with status 'done'
#9 160.2         Preparing metadata (pyproject.toml): started
#9 160.2         Preparing metadata (pyproject.toml): finished with status 'done'
#9 160.2       Collecting preshed<3.1.0,>=3.0.2
#9 160.2         Downloading preshed-3.0.6.tar.gz (14 kB)
#9 160.2         Installing build dependencies: started
#9 160.2         Installing build dependencies: still running...
#9 160.2         Installing build dependencies: finished with status 'error'
#9 160.2         error: subprocess-exited-with-error
#9 160.2       
#9 160.2         × pip subprocess to install build dependencies did not run successfully.
#9 160.2         │ exit code: 1
#9 160.2         ╰─> [62 lines of output]
#9 160.2             Collecting setuptools
#9 160.2               Using cached setuptools-60.6.0-py3-none-any.whl (953 kB)
#9 160.2             Collecting cython>=0.28
#9 160.2               Using cached Cython-0.29.27-cp38-cp38-musllinux_1_1_x86_64.whl (2.1 MB)
#9 160.2             Collecting cymem<2.1.0,>=2.0.2
#9 160.2               Using cached cymem-2.0.6.tar.gz (8.2 kB)
#9 160.2               Installing build dependencies: started
#9 160.2               Installing build dependencies: finished with status 'done'
#9 160.2               Getting requirements to build wheel: started
#9 160.2               Getting requirements to build wheel: finished with status 'done'
#9 160.2               Installing backend dependencies: started
#9 160.2               Installing backend dependencies: finished with status 'done'
#9 160.2               Preparing metadata (pyproject.toml): started
#9 160.2               Preparing metadata (pyproject.toml): finished with status 'done'
#9 160.2             Collecting murmurhash<1.1.0,>=0.28.0
#9 160.2               Downloading murmurhash-1.0.6.tar.gz (12 kB)
#9 160.2               Installing build dependencies: started
#9 160.2               Installing build dependencies: finished with status 'done'
#9 160.2               Getting requirements to build wheel: started
#9 160.2               Getting requirements to build wheel: finished with status 'done'
#9 160.2               Installing backend dependencies: started
#9 160.2               Installing backend dependencies: finished with status 'done'
#9 160.2               Preparing metadata (pyproject.toml): started
#9 160.2               Preparing metadata (pyproject.toml): finished with status 'done'
#9 160.2             Building wheels for collected packages: cymem, murmurhash
#9 160.2               Building wheel for cymem (pyproject.toml): started
#9 160.2               Building wheel for cymem (pyproject.toml): finished with status 'error'
#9 160.2               error: subprocess-exited-with-error
#9 160.2       
#9 160.2               × Building wheel for cymem (pyproject.toml) did not run successfully.
#9 160.2               │ exit code: 1
#9 160.2               ╰─> [7 lines of output]
#9 160.2                   running bdist_wheel
#9 160.2                   running build
#9 160.2                   running build_py
#9 160.2                   package init file 'cymem/tests/__init__.py' not found (or not a regular file)
#9 160.2                   running build_ext
#9 160.2                   building 'cymem.cymem' extension
#9 160.2                   error: command 'gcc' failed: No such file or directory
#9 160.2                   [end of output]
#9 160.2       
#9 160.2               note: This error originates from a subprocess, and is likely not a problem with pip.
#9 160.2               ERROR: Failed building wheel for cymem
#9 160.2               Building wheel for murmurhash (pyproject.toml): started
#9 160.2               Building wheel for murmurhash (pyproject.toml): finished with status 'error'
#9 160.2               error: subprocess-exited-with-error
#9 160.2       
#9 160.2               × Building wheel for murmurhash (pyproject.toml) did not run successfully.
#9 160.2               │ exit code: 1
#9 160.2               ╰─> [6 lines of output]
#9 160.2                   running bdist_wheel
#9 160.2                   running build
#9 160.2                   running build_py
#9 160.2                   running build_ext
#9 160.2                   building 'murmurhash.mrmr' extension
#9 160.2                   error: command 'gcc' failed: No such file or directory
#9 160.2                   [end of output]
#9 160.2       
#9 160.2               note: This error originates from a subprocess, and is likely not a problem with pip.
#9 160.2               ERROR: Failed building wheel for murmurhash
#9 160.2             Failed to build cymem murmurhash
#9 160.2             ERROR: Could not build wheels for cymem, murmurhash, which is required to install pyproject.toml-based projects
#9 160.2             [end of output]
#9 160.2       
#9 160.2         note: This error originates from a subprocess, and is likely not a problem with pip.
#9 160.2       error: subprocess-exited-with-error
#9 160.2       
#9 160.2       × pip subprocess to install build dependencies did not run successfully.
#9 160.2       │ exit code: 1
#9 160.2       ╰─> See above for output.
#9 160.2       
#9 160.2       note: This error originates from a subprocess, and is likely not a problem with pip.
#9 160.2       [end of output]
#9 160.2   
#9 160.2   note: This error originates from a subprocess, and is likely not a problem with pip.
#9 160.2 error: subprocess-exited-with-error
#9 160.2 
#9 160.2 × pip subprocess to install build dependencies did not run successfully.
#9 160.2 │ exit code: 1
#9 160.2 ╰─> See above for output.
#9 160.2 
#9 160.2 note: This error originates from a subprocess, and is likely not a problem with pip.
------
executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 1

UPDATE:在运行pip之前添加RUN apk add gcc之后,我现在在轮构建时得到不同的错误:

#10 154.1               × Building wheel for murmurhash (pyproject.toml) did not run successfully.
#10 154.1               │ exit code: 1
#10 154.1               ╰─> [8 lines of output]
#10 154.1                   running bdist_wheel
#10 154.1                   running build
#10 154.1                   running build_py
#10 154.1                   running build_ext
#10 154.1                   building 'murmurhash.mrmr' extension
#10 154.1                   gcc: fatal error: cannot execute 'cc1plus': execvp: No such file or directory
#10 154.1                   compilation terminated.
#10 154.1                   error: command '/usr/bin/gcc' failed with exit code 1
#10 154.1                   [end of output]
pzfprimi

pzfprimi1#

问题发生在python版本中,因此请将您的命令更改为仅

RUN python -m pip install --upgrade pip

RUN pip install -r requirements.txt

RUN python -m spacy download en_core_web_sm

如果给予错误,请尝试以下操作:

RUN python3 -m pip install --upgrade pip

RUN pip install -r requirements.txt

RUN python3 -m spacy download en_core_web_sm

相关问题