Python 3.9 中 h5py 的 Docker 构建失败

问题描述 投票:0回答:1

这里是 Docker 新手。我一直在尝试创建一个简单的流式应用程序。当我尝试使用 Dockerfile 构建 docker 映像时,构建失败并抛出以下错误:

ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects

我经历了这个平台上提供的很多解决方案。他们都没有修复 docker 构建。我通过homebrew安装了hdf5。导出环境变量如下:

HDF5_DIR="$(brew --prefix hdf5)"
。所有解决方案均无效,我仍然面临同样的问题。这就是我的 Dockerfile 的样子:

FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN pip install h5py
EXPOSE 80 # Ignore this
ENTRYPOINT ["streamlit", "run"] # Ignore this
CMD ["main.py"] # Ignore this

我认为h5py已经成功安装到我的本地机器上。我在本地机器上测试了streamlit应用程序(我使用的是MacBook Air M1。Python版本是3.9.6)。一切正常。我认为问题出在我选择的 Python 镜像上,所以我将 Dockerfile 的第一行更改为

FROM python:3.9.6
。这导致了不同类型的错误:
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

以下是库,我从

requirements.txt
文件安装:

absl-py==2.1.0
altair==5.3.0
astunparse==1.6.3
attrs==23.2.0
blinker==1.7.0
cachetools==5.3.3
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
contourpy==1.2.1
cycler==0.12.1
flatbuffers==24.3.25
fonttools==4.51.0
gast==0.5.4
gitdb==4.0.11
GitPython==3.1.43
google-pasta==0.2.0
grpcio==1.62.2
h5py>=3.10.0
idna==3.7
importlib_metadata==7.1.0
importlib_resources==6.4.0
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
keras==3.2.1
kiwisolver==1.4.5
libclang==18.1.1
Markdown==3.6
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.8.4
mdurl==0.1.2
ml-dtypes==0.3.2
namex==0.0.8
numpy==1.26.4
opt-einsum==3.3.0
optree==0.11.0
packaging==24.0
pandas==2.2.2
pillow==10.3.0
protobuf==4.25.3
pyarrow==15.0.2
pydeck==0.8.1b0
Pygments==2.17.2
pyparsing==3.1.2
python-dateutil==2.9.0.post0
pytz==2024.1
referencing==0.34.0
requests==2.31.0
rich==13.7.1
rpds-py==0.18.0
six==1.16.0
smmap==5.0.1
streamlit==1.33.0
tenacity==8.2.3
tensorboard==2.16.2
tensorboard-data-server==0.7.2
tensorflow==2.16.1
tensorflow-io-gcs-filesystem==0.36.0
termcolor==2.4.0
toml==0.10.2
toolz==0.12.1
tornado==6.4
typing_extensions==4.11.0
tzdata==2024.1
urllib3==2.2.1
Werkzeug==3.0.2
wrapt==1.16.0
zipp==3.18.1

对于解决此问题的任何形式的帮助,我们将不胜感激。我花了半天的时间来研究解决方案并试图解决这个问题。谢谢。

python docker numpy tensorflow h5py
1个回答
0
投票

来自 python:3.9-slim

更新点

运行 pip install --升级 pip

使用apt安装HDF5

运行 apt-get update && apt-get install -y libhdf5-dev

复制。并设置工作目录

复制。 /应用程序 工作目录/应用程序

使用非二进制标志安装 h5py

运行 pip install --no-binary h5py h5py

EXPOSE 80 # 忽略这个 ENTRYPOINT ["streamlit", "run"] # 忽略这个 CMD ["main.py"] # 忽略这个

© www.soinside.com 2019 - 2024. All rights reserved.