skip to Main Content

A newbie to Docker here. I have been trying to create a simple streamlit application. When I tried to build the docker image using the Dockerfile, the build failed throwing the following error: ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects.

I went through so many solutions provided on this platform. None of them worked in fixing the docker build. I installed hdf5 through homebrew. Exported the env variable as such: HDF5_DIR="$(brew --prefix hdf5)". None of the solutions worked and I am still facing the same issue. This is how my Dockerfile looks like:

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

I think, h5py has been installed successfully to my local machine. I tested the streamlit app in my local machine (I am using a MacBook Air M1. The Python version is 3.9.6). It was working fine. I thought the issue was with the Python image I have chosen, so I changed the first line of the Dockerfile to FROM python:3.9.6. This resulted in a different type of error: ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

Following are the libraries, I am installing from the requirements.txt file:

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

Any kind of assistance in resolving this issue will be appreciated. I have spent like half a day going through solutions and trying to fix this. Thank you.

2

Answers


  1. FROM python:3.9-slim
    
    # Update pip
    RUN pip install --upgrade pip
    
    # Install HDF5 using apt
    RUN apt-get update && apt-get install -y libhdf5-dev
    
    # Copy . and set working directory
    COPY . /app
    WORKDIR /app
    
    # Install h5py with no-binary flag
    RUN pip install --no-binary h5py h5py
    
    EXPOSE 80 # Ignore this
    ENTRYPOINT ["streamlit", "run"] # Ignore this
    CMD ["main.py"] # Ignore this
    
    Login or Signup to reply.
  2. Thanks very much for you suggestion.

    apt-get update && apt-get install -y libhdf5-dev
    and
    pip install –no-binary h5py h5py
    worked for me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search