error in installing tf 2.3 on raspberry 4

I am very new to Balena Os. I have installed Balena Os successfully on my raspberry pi 4. But when i try to install my tensorflow 2.3 wheel on it i am getting this error :

Step 32/47 : RUN pip3 install tensorflow-2.3.0-cp37-none-linux_armv7l.whl
[main]      ---> Running in 4145d98ce2ec
[main]     Processing ./tensorflow-2.3.0-cp37-none-linux_armv7l.whl
[main]     ERROR: Exception:
[main]     Traceback (most recent call last):
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/", line 180, in _main
[main]         status =, args)
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/", line 205, in wrapper
[main]         return func(self, options, args)
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/", line 319, in run
[main]         reqs, check_supported_wheels=not options.target_dir
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 104, in resolve
[main]         req, requested_extras=()
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 434, in make_requirement_from_install_req
[main]         version=None,
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 205, in _make_candidate_from_link
[main]         version=version,
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 312, in __init__
[main]         version=version,
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 151, in __init__
[main]         self.dist = self._prepare()
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 234, in _prepare
[main]         dist = self._prepare_distribution()
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/", line 318, in _prepare_distribution
[main]         self._ireq, parallel_builds=True
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/", line 508, in prepare_linked_requirement
[main]         return self._prepare_linked_requirement(req, parallel_builds)
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/", line 571, in _prepare_linked_requirement
[main]         req, self.req_tracker, self.finder, self.build_isolation,
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/", line 61, in _get_prepared_distribution
[main]         return abstract_dist.get_pkg_resources_distribution()
[main]       File "/usr/local/lib/python3.7/site-packages/pip/_internal/distributions/", line 27, in get_pkg_resources_distribution
[main]         with ZipFile(self.req.local_file_path, allowZip64=True) as z:
[main]       File "/usr/local/lib/python3.7/", line 1258, in __init__
[main]         self._RealGetContents()
[main]       File "/usr/local/lib/python3.7/", line 1325, in _RealGetContents
[main]         raise BadZipFile("File is not a zip file")
[main]     zipfile.BadZipFile: File is not a zip file

I tried all the troubleshooting steps but could not solve the error. Anything else I am doing wrong or i can do?

Happy to help you out. Can you provide us more context on what are you trying to do + It would be really helpful if you are able to paste the entire Dockerfile that you are using for the build? It would help us debug your issue much more easily. Also, I was able to find a relevant Stackoverflow answer that might help with this - python - pip3 cannot install .whl files on raspberry pi: File is not a zip file - Stack Overflow

Sure. I am trying to install tensorflow 2.3 on raspberry pi 4 through a docker container.

the dockerfile is as below:

FROM balenalib/armv7hf-python:3.7

RUN apt-get update

# 2021-06-08 ADM eliminating a warning
RUN apt-get -y install apt-utils

RUN apt -y install libaec0 libaom0 libatk-bridge2.0-0 libatk1.0-0 libatlas3-base libatspi2.0-0 libavcodec58 libavformat58 libavutil56 libbluray2 libcairo-gobject2 libcairo2 libchromaprint1 libcodec2-0.8.1 libcroco3 libdatrie1 libdrm2 libepoxy0 libfontconfig1 libgdk-pixbuf2.0-0 libgfortran5 libgme0 libgraphite2-3 libgsm1 libgtk-3-0 libharfbuzz0b libhdf5-103 libilmbase23 libjbig0 libmp3lame0 libmpg123-0 libogg0 libopenexr23 libopenjp2-7 libopenmpt0 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 librsvg2-2 libshine3 libsnappy1v5 libsoxr0 libspeex1 libssh-gcrypt-4 libswresample3 libswscale5 libsz2 libthai0 libtheora0 libtiff5 libtwolame0 libva-drm2 libva-x11-2 libva2 libvdpau1 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx5 libwavpack1 libwayland-client0 libwayland-cursor0 libwayland-egl1 libwebp6 libwebpmux3 libx264-155 libx265-165 libxcb-render0 libxcb-shm0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0 libxrandr2 libxrender1 libxvidcore4 libzvbi0
RUN apt-get -y install libhdf5-dev libc-ares-dev libeigen3-dev
RUN apt-get -y install libatlas-base-dev libopenblas-dev libblas-dev
RUN apt-get -y install liblapack-dev
RUN apt-get -y install ffmpeg

# 2021-06-08 ADM fix numpy failures
RUN apt-get -y install make automake gcc g++ subversion python3-dev

# 2021-06-10 ADM fix wget failures
# 2021-06-18 ADM added unzip
# 2021-06-18 ADM added kmod to setup camera
RUN apt-get -y install wget unzip kmod

RUN mkdir workspace
RUN mkdir installation_files

COPY opencv_contrib_python- /installation_files
COPY tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl /installation_files
COPY scipy-1.4.1-cp37-cp37m-linux_armv7l.whl /installation_files
COPY tensorflow-2.3.0-cp37-none-linux_armv7l.whl /installation_files

WORKDIR /installation_files

# 2021-06-08 ADM fixing a pip warning
RUN pip3 install --upgrade pip

# 2021-06-08 ADM fixing a build problem
RUN pip3 install wheel

RUN pip3 install numpy==1.17
RUN pip3 install opencv_contrib_python-
RUN pip3 install tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl
RUN pip3 install scipy-1.4.1-cp37-cp37m-linux_armv7l.whl

RUN pip3 install pybind11
RUN pip3 install Cython==0.29.21
RUN pip3 install h5py

RUN apt-get -y install build-essential cmake
RUN pip3 install dlib

RUN pip3 install tensorflow-2.3.0-cp37-none-linux_armv7l.whl

RUN pip3 install pymongo
RUN pip3 install python-decouple==3.4
RUN pip3 install pyarmor
RUN pip3 install imutils
RUN pip3 install "picamera[array]"
RUN apt-get -y install nano

# 2021-06-18 ADM installing VIM for editing
RUN apt-get -y install vim

# 2021-06-10 ADM adding bash to run the main loop
RUN apt-get -y install bash

Also i have tried the approach of the stackoverflow answer, but still no luck. The wheel i am using is not corrupt.

Thanks for the Dockerfile, can you send me the link for the source from where you are fetching the Tensorflow wheel (or are you compiling it yourself). I don’t see that step in your Dockerfile as you COPY the wheels from your local machine into the build. I am not familiar with the installation of Tensorflow but it seems that each Tensorflow version works well with a particular Python version. Reading this article here, it seems like Tf 2.3.0 works with Python 3.5, hence it might be a good idea to use the base image with Python version 3.5? Hope it helps.

Also, several optimizations that you can perform would be to use:

  1. Use %%BALENA_MACHINE_NAME%% for your base image, that way no matter which device you end up using you will be using the right base image - Balena base images - Balena Documentation
  2. With balenalib base images, you can use the utility of install_packages to club all the apt-get installations steps onto a single layer which would end up optimizing your build by quite a lot (Balena base images - Balena Documentation).
  3. If you are looking to optimize even further later on, then for that

Hey @prapti1998, just wanted to see if the suggestion about using an updated Python version helped?

No, it did not. I finally found that there was a numpy version issue. The compatible version of numpy with respect to tf 2.3 had to be installed.

Thanks for your help @vipulgupta2048 @toochevere