OK, after spending hours, I found the problem and fixed it. So I'll answer my own question.

First of all, I was using --no-deps parameter in the pip wheel command. This parameter causes that the pip wheel only downloads the main packages, without their dependencies. So in the second build image (stage), pip was trying to download all the sub dependencies for these main dependencies. So these dependencies were in need for some system packages to build.

Removing this --no-deps parameter would normally fix the problem in such situation, but it caused another error for my situation. There were some version conflicts between the dependencies, which were not exist with regular pip install -r ...

Instead of the pip wheel technique, I just used pip install --user -r option to install my requirements in the folder /root/.local. Then I moved the /root/.local folder to the second stage's /root:

..
COPY --from=builder /root/.local /home/.local
..

That's all. All my requirements were installed in the second build image too.

Do not forget to add the /root/.local/bin path to your $PATH:

ENV PATH=/root/.local/bin:$PATH
Answer from kozhioyrin on Stack Overflow
🌐
Readthedocs
docker-sean.readthedocs.io › en › latest › reference › pip_wheel.html
pip wheel — docker 6.1.0.dev0 documentation
This command must create a wheel compatible with the invoking Python interpreter, and save that wheel in the directory TARGET.
🌐
Docker Community
forums.docker.com › general
Docker Desktop shows image has a python wheel vulnerability even though it has been updated - General - Docker Community Forums
May 13, 2023 - Not sure what i’m missing and cannot find anything helpful while searching around the internet. I’m working on building a docker image and am able to do so without issue. However, for reasons that are not evident nor apparent, docker desktop declares that the built image has 1 H (high) vulnerability because it claims the wheel package is version 0.37.1. Clicking through the link provides zero information about how to remediate this and searching around the web also provides no help.
🌐
GitHub
github.com › testdrivenio › python-docker-wheel
GitHub - testdrivenio/python-docker-wheel · GitHub
Contribute to testdrivenio/python-docker-wheel development by creating an account on GitHub.
Starred by 7 users
Forked by 10 users
Languages   Python
🌐
PyPI
pypi.org › project › docker
docker · PyPI
If you're not sure about the file name format, learn more about wheel file names. Copy a direct link to the current filters Copy · File name · Interpreter · Interpreter · py3 · ABI · ABI · none · Platform · Platform · any · docker-7.1.0-py3-none-any.whl (147.8 kB view details) Uploaded May 23, 2024 Python 3 ·
      » pip install docker
    
Published   May 23, 2024
Version   7.1.0
🌐
Towards Data Science
towardsdatascience.com › home › latest › running python wheel tasks in custom docker containers in databricks
Running Python Wheel Tasks in Custom Docker Containers in Databricks | Towards Data Science
March 5, 2025 - The first stage is the base image that uses **Databricks Runtime Python 12.2-LTS*** as the base image and sets the working directory to /app. It also updates pip. *We can also build our own base image, as long as we have certain libraries installed: Build your own Docker base · The second stage is the builder image that installs Poetry, copies the application files (including pyproject.toml, poetry.lock, and README.md) and builds a wheel using Poetry.
🌐
GitHub
github.com › Canuteson › wheel-builder
GitHub - Canuteson/wheel-builder: Docker container for building Python wheels with PyPy
Docker container for building Python wheels with PyPy - Canuteson/wheel-builder
Author   Canuteson
Find elsewhere
🌐
Samroeca
samroeca.com › docker-python-install-wheels.html
Smaller python docker containers | Sam's world
It relies heavily on multi-stage builds and on pip wheels. Copy the following code into a file called “Dockerfile.small”: ########################################### # Throwaway image with C compiler installed FROM python:3.6-alpine as bigimage # install the C compiler RUN apk add --no-cache linux-headers g++ # instead of installing, create a wheel RUN pip wheel --wheel-dir=/root/wheels uwsgi ########################################### # Image WITHOUT C compiler but WITH uWSGI FROM python:3.6-alpine as smallimage COPY --from=bigimage /root/wheels /root/wheels # Ignore the Python package index # and look for archives in # /root/wheels directory RUN pip install \ --no-index \ --find-links=/root/wheels \ uwsgi
🌐
Python.org
discuss.python.org › packaging
How to delete wheel, setuptools and pip packages from the base python installation in a Docker image - Packaging - Discussions on Python.org
May 16, 2023 - I’m interested in eliminating the wheel, setuptools, and pip packages from the base Python installation in /usr/local/lib/python3.9/site-packages after installing some packages in a virtual enviroment. What is the correc…
🌐
TestDriven.io
testdriven.io › blog › docker-best-practices
Docker Best Practices for Python Developers | TestDriven.io
February 12, 2024 - RUN pip install --no-cache /wheels/* In this example, the GCC compiler is required for installing certain Python packages, so we added a temp, build-time stage to handle the build phase. Since the final run-time image does not contain GCC, it's much lighter and more secure. ... REPOSITORY TAG IMAGE ID CREATED SIZE docker...
🌐
CodeRivers
coderivers.org › blog › python-dockerfile-is-wheel-required
Python Dockerfile: Is Wheel Required? - CodeRivers
February 22, 2026 - For example, to build wheels for your project's dependencies, you can use pip wheel: bash pip wheel -r requirements.txt -w wheels/ This command will download and build wheels for all the packages listed in requirements.txt and save them in the wheels/ directory. Create the Dockerfile Here is a basic Dockerfile example for building a Python Docker image using wheels: ```Dockerfile # Use a base Python image FROM python:3.9-slim
🌐
MIKI BLOG
blog.mikihands.com › home › docker › understanding and utilizing python wheel to speed up docker builds
Understanding and Utilizing Python Wheel to Speed Up Docker Builds
November 20, 2025 - A Docker build utilizing Wheel primarily involves creating Wheel files in the Builder Stage and then copying and installing them in the Final Stage. Below is a pattern for efficiently installing packages with C library dependencies.
🌐
Stack Overflow
stackoverflow.com › questions › 62334562 › how-to-build-a-python-package-with-a-c-extension-as-a-wheel-for-docker
How to build a python package with a c extension as a wheel for docker - Stack Overflow
I am trying to build a python package with a c extension to be used in a Docker container. ... CopyFROM python:3.8-slim-buster WORKDIR /home/user COPY --chown=user:user requirements.txt /tmp/requirements.txt RUN python -m venv user RUN user/bin/pip install -r /tmp/requirements.txt RUN user/bin/pip install wheel RUN user/bin/pip install my_c_package-0.0.1-py3-none-any.whl USER user ...
🌐
Real Python
realpython.com › offline-python-deployments-with-docker
Build Robust Continuous Integration With Docker and Friends – Real Python
May 5, 2023 - When it comes to writing unit tests, it’s quite common for those in the Python community to choose pytest over the standard library’s unittest module. Thanks to the relative simplicity of pytest, this testing framework is quick to start with. Go ahead and add pytest as an optional dependency to your project: ... # pyproject.toml [build-system] requires = ["setuptools>=67.0.0", "wheel"] build-backend = "setuptools.build_meta" [project] name = "page-tracker" version = "1.0.0" dependencies = [ "Flask", "redis", ] [project.optional-dependencies] dev = [ "pytest", ]
🌐
GitHub
github.com › moonbuggy › docker-python-musl-wheels
GitHub - moonbuggy/docker-python-musl-wheels: Python musl wheels built in Alpine Linux for a variety of CPU architectures.
August 10, 2022 - This repo generates Docker images containing wheel files for the module and python version specified by the image tag (older images also specify the architecture in the tags). These images are intended to be used as part of a multi-stage Docker image build, providing pre-built wheels to a Python stage.
Author   moonbuggy
🌐
Docker Hub
hub.docker.com › r › moonbuggy2000 › python-musl-wheels
moonbuggy2000/python-musl-wheels - Docker Image
This repo generates Docker images containing wheel files for the module and python version specified by the image tag (older images also specify the architecture in the tags). These images are intended to be used as part of a multi-stage Docker image build, providing pre-built wheels to a Python stage.
🌐
GitHub
github.com › praekeltfoundation › debian-wheel-mirror
GitHub - praekeltfoundation/debian-wheel-mirror: Automated Python wheel building and deployment for Docker containers · GitHub
Automated Python wheel building and deployment for Docker containers - praekeltfoundation/debian-wheel-mirror
Author   praekeltfoundation
🌐
GitHub
github.com › ChristianWitts › wheel-builder
GitHub - ChristianWitts/wheel-builder: A simple Docker based solution to generate Python wheels · GitHub
A simple Docker based solution to generate Python wheels - ChristianWitts/wheel-builder
Author   ChristianWitts