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 ... invoking Python interpreter, and save that wheel in the directory TARGET. No other build system commands are invoked by the pip wheel command. It is possible using --global-option to include additional build commands with their arguments in the setup.py command.
Discussions

Anyone know a 'preferred' way to install wheels into docker containers?

Our approach is to have a wheelbuilder container with all the building dependencies etc in that image, once all wheels are built into a shared volume can be "consumed" by other containers just pointing pip to that folder. It works pretty well for us.

More on reddit.com
🌐 r/Python
10
7
October 28, 2014
python - With multi-stage Dockerfile, the pip wheel still needs the dependencies from the base builder - Stack Overflow
I am new to the Docker environment. So, sorry if asking this is a common thing. I'm using the Dockerfile below, which first uses a builder to make things with the wheel. The problem is that the More on stackoverflow.com
🌐 stackoverflow.com
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. I create a python wheel as follows: python install bdist_wheel and the package looks (more or less) like More on stackoverflow.com
🌐 stackoverflow.com
My Python Docker build takes hours to build.
What you should do is build PyTorch and then push it to a registry, and use that as your base image to start each build. It will save you having to rebuild it each time since it will be prebuilt inside of the base image. More on reddit.com
🌐 r/docker
40
31
September 10, 2024
🌐
Samroeca
samroeca.com › docker-python-install-wheels.html
Smaller python docker containers | Sam's world
This final example results in a small image with uWSGI installed and without a C compiler. 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
🌐
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.
🌐
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. # [Stage 1] Builder: Create Wheel file FROM python:3.9-slim as builder # Install essential packages for compilation (not included in final image) RUN apt-get update && apt-get install -y \ build-essential \ gcc \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy requirements.txt COPY requirements.txt .
🌐
GitHub
github.com › steeef › docker-python-wheel
GitHub - steeef/docker-python-wheel: Use Docker to assist in building wheel files to be used with Python pip · GitHub
docker build -t docker-python-wheel docker run -d -v $PWD/wheels:/wheels docker-python-wheel \ <python_package>==<version>...
Author   steeef
Find elsewhere
🌐
CodeRivers
coderivers.org › blog › python-dockerfile-is-wheel-required
Python Dockerfile: Is Wheel Required? - CodeRivers
February 22, 2026 - If you already have wheels available ... a local wheels/ directory. For example: FROM python:3.9-slim WORKDIR /app # Install wheels from a remote location RUN pip install --find-links=https://example.com/wheels -r requirements.txt COPY....
🌐
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
🌐
GitHub
github.com › pypa › manylinux
GitHub - pypa/manylinux: Python wheels that work on any linux (almost) · GitHub
Native dependencies are all pinned in the Dockerfile. To update the pins, run the dedicated nox session. This will add a commit for each update. If you only want to see what would be updated, you can do a dry run: $ nox -s update_native_dependencies [-- --dry-run] An example project which builds x86_64 wheels for each Python interpreter version can be found here: https://github.com/pypa/python-manylinux-demo.
Starred by 1.7K users
Forked by 243 users
Languages   Shell 56.1% | Python 32.9% | Dockerfile 9.8% | C 0.4% | CMake 0.4% | C++ 0.3% | M4 0.1%
🌐
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 - The pip wheel command in the Dockerfile can be overridden by putting a custom command in the scripts/<module_name>.sh file and setting WHEEL_BUILT_IN_SCRIPT to prevent the default command executing. The mod_depends function is called by the build system during post-checkout to fetch any required modules from this repo (falling back to PyPi if they're not found), and these dependencies will be installed before the Dockerfile begins building the module. See scripts/paramiko.sh for an example. GitHub: https://github.com/moonbuggy/docker-python-musl-wheels
Author   moonbuggy
🌐
GitHub
github.com › ChristianWitts › wheel-builder
GitHub - ChristianWitts/wheel-builder: A simple Docker based solution to generate Python wheels · GitHub
#!/usr/bin/env sh REQ_HASH=$(git log -n 1 --pretty=format:%H -- requirements.txt) CUR_HASH=$(git log -n 1 --pretty=format:%H) if [ $REQ_HASH == $CUR_HASH ]; then ./crosscompile.sh twine upload \ -r pypi.example.com \ -u username \ -p super-secret \ --skip-existing \ target/* fi · Some packages, most notably for me is MySQL-python==1.2.4 will fail to build, which would require manually downloading the archive, unpacking, and running python setup.py bdist_wheel --universal manually, and grabbing the wheel from the dist directory.
Author   ChristianWitts
🌐
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", ]
🌐
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 ...
🌐
Docker Hub
hub.docker.com › r › moonbuggy2000 › python-musl-wheels
moonbuggy2000/python-musl-wheels - Docker Image
The pip wheel command in the Dockerfile can be overridden by putting a custom command in the scripts/<module_name>.sh file and setting WHEEL_BUILT_IN_SCRIPT to prevent the default command executing. The mod_depends function is called by the build system during post-checkout to fetch any required modules from this repo (falling back to PyPi if they're not found), and these dependencies will be installed before the Dockerfile begins building the module. See scripts/paramiko.sh⁠ for an example. GitHub: https://github.com/moonbuggy/docker-python-musl-wheels⁠
🌐
DeepWiki
deepwiki.com › molinfo-vienna › CDPKit › 6.2-wheel-building-with-docker
Python Wheel Building with Docker | molinfo-vienna/CDPKit | DeepWiki
December 9, 2025 - CDPKit uses two Docker container variants for building manylinux-compatible wheels: manylinux_2_28 - Based on newer glibc version, supporting modern Linux distributions · manylinux2014 - Based on older glibc version, providing broader compatibility with older Linux distributions · Each container is configured with all the necessary dependencies to build CDPKit Python extensions, including:
🌐
PyPI
pypi.org › project › docker
docker · PyPI
Maintainer: Docker Inc. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names.
      » pip install docker
    
Published   May 23, 2024
Version   7.1.0
🌐
GitHub
github.com › public › docker-on-wheels
GitHub - public/docker-on-wheels: Some scripts for making life life with Wheels in Docker containers easier · GitHub
Add system build dependencies to app/wheel-build-dep-packages.txt · Add desired things to build to app/requirements.txt · Setup app/Dockerfile to load the wheels. e.g. ADD .wheels /var/cache/wheels and point pip at them with --find-links.
Author   public
🌐
Readthedocs
nrn.readthedocs.io › en › latest › install › python_wheels.html
Building Python Wheels — NEURON documentation
cd nrn/packaging/python # update Dockerfile docker build -t neuronsimulator/neuron_wheel:<tag> .