【问题标题】:Error while building a Docker Image. "Exception: Cython-generated file 'pandas/_libs/algos.c' not found."构建 Docker 映像时出错。 “例外:找不到 Cython 生成的文件‘pandas/_libs/algos.c’。”
【发布时间】:2021-12-21 19:36:18
【问题描述】:

我以前可以基于以下构建docker镜像

Dockerfile

FROM python:3.7 

COPY ./* ./app/
WORKDIR /app/

RUN pip install -r requirements.txt

EXPOSE 80
CMD ["python", "application.py"]

requirements.txt

Flask==1.1.1
Werkzeug==1.0.1
Flask-Cors==3.0.8
pandas==0.25.0

但由于某种原因,现在出现以下错误:

Exception: Cython-generated file 'pandas/_libs/algos.c' not found.

Cython is required to compile pandas from a development branch.

Please Cython or download a release package of pandas.
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sj5w0hrl/pandas_95358ad691f84ba592a47a0ee2865610/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sj5w0hrl/pandas_95358ad691f84ba592a47a0ee2865610/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gq03hxk9/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/pandas Check the logs for full command output.
#8 29.80 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#8 29.80 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

也观察到了

Building wheel for pandas (setup.py): started 在此过程的早期。

我能够在 anaconda python 3.7 环境中运行 application.py,使用完全相同的库版本,但不确定为什么无法构建 Docker 映像。

任何指针将不胜感激!

【问题讨论】:

  • 那些部门都超级老——尝试使用更现代的版本

标签: python pandas docker pip containers


【解决方案1】:

运行您的代码 sn-p 时似乎没有出现任何问题

❯ docker build --progress=plain .
#1 [internal] load build definition from Dockerfile
#1 sha256:4e71406ebab08442ac664cde223b092f6776344e6fb4ddfdff4dfbb838bcfe9e
#1 transferring dockerfile: 172B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:1a10e5d0ab49608585f614ecfaa0bfe97ccc2d31060e198df8a1980e44458991
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/python:3.7
#3 sha256:2e83735093f2e645c7660e349795ae80186113afc054af8bdc7501e99da12131
#3 DONE 0.2s

#5 [internal] load build context
#5 sha256:8f0c2f0a3180ca58eaa2b66c92cb89696bbb21d93d9d0ff7c39d98d55b355606
#5 transferring context: 624B done
#5 DONE 0.0s

#4 [1/4] FROM docker.io/library/python:3.7@sha256:c185410ab69dcdfb5e5edabf0d78bc5655a210a4e263001b4bc4bc1d9e6f6309
#4 sha256:fd9bad7021e0dc27c7bb2b55e29fecf8c8a6ad84d1c7159ed9eaa62a493ba344
#4 CACHED

#6 [2/4] COPY ./* ./app/
#6 sha256:d40647c650fc7755d12ce659cd5a785a62d11f98b65cdde20f0bd9d6686bd152
#6 DONE 0.0s

#7 [3/4] WORKDIR /app/
#7 sha256:6ea14a12742c3186cb146b56b90cef310260d2bd5ac17ced3c64f2a2f8716543
#7 DONE 0.0s

#8 [4/4] RUN pip install -r requirements.txt
#8 sha256:0f52dc2b38d612e5f77fa250cd659dbb1193e621e6e17858778f965f0bc9f3e2
#8 1.260 Collecting Flask==1.1.1
#8 1.303   Downloading Flask-1.1.1-py2.py3-none-any.whl (94 kB)
#8 1.381 Collecting Werkzeug==1.0.1
#8 1.394   Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
#8 1.489 Collecting Flask-Cors==3.0.8
#8 1.498   Downloading Flask_Cors-3.0.8-py2.py3-none-any.whl (14 kB)
#8 1.784 Collecting pandas==0.25.0
#8 1.806   Downloading pandas-0.25.0-cp37-cp37m-manylinux1_x86_64.whl (10.4 MB)
#8 4.294 Collecting itsdangerous>=0.24
#8 4.317   Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
#8 4.403 Collecting Jinja2>=2.10.1
#8 4.428   Downloading Jinja2-3.0.2-py3-none-any.whl (133 kB)
#8 4.568 Collecting click>=5.1
#8 4.585   Downloading click-8.0.3-py3-none-any.whl (97 kB)
#8 4.675 Collecting Six
#8 4.695   Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
#8 4.922 Collecting pytz>=2017.2
#8 4.941   Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB)
#8 5.577 Collecting numpy>=1.13.3
#8 5.590   Downloading numpy-1.21.4-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)
#8 9.649 Collecting python-dateutil>=2.6.1
#8 9.658   Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
#8 9.847 Collecting importlib-metadata
#8 9.853   Downloading importlib_metadata-4.8.2-py3-none-any.whl (17 kB)
#8 9.971 Collecting MarkupSafe>=2.0
#8 9.982   Downloading MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (31 kB)
#8 10.10 Collecting zipp>=0.5
#8 10.11   Downloading zipp-3.6.0-py3-none-any.whl (5.3 kB)
#8 10.15 Collecting typing-extensions>=3.6.4
#8 10.16   Downloading typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
#8 10.29 Installing collected packages: zipp, typing-extensions, MarkupSafe, importlib-metadata, Werkzeug, Six, Jinja2, itsdangerous, click, pytz, python-dateutil, numpy, Flask, pandas, Flask-Cors
#8 14.42 Successfully installed Flask-1.1.1 Flask-Cors-3.0.8 Jinja2-3.0.2 MarkupSafe-2.0.1 Six-1.16.0 Werkzeug-1.0.1 click-8.0.3 importlib-metadata-4.8.2 itsdangerous-2.0.1 numpy-1.21.4 pandas-0.25.0 python-dateutil-2.8.2 pytz-2021.3 typing-extensions-3.10.0.2 zipp-3.6.0
#8 14.42 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#8 14.55 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#8 14.55 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
#8 DONE 14.7s

#9 exporting to image
#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#9 exporting layers
#9 exporting layers 1.0s done
#9 writing image sha256:724cd048bd29bea338521b611527e448b3fc563e3cd0569a9a693bafb2c6018d done
#9 DONE 1.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-29
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 2018-04-23
    相关资源
    最近更新 更多