6

I am using docker tutorial (https://docs.docker.com/language/python/build-images/) to build a simple python app. Using freeze command I made requirements.txt file which consists a lot of packages.

When I want to build the docker image, I am getting this error:

Step 4/6 : RUN pip3 install -r requirements.txt ---> Running in f92acd21d271

ERROR: Could not find a version that satisfies the requirement apt-clone==0.2.1 (from versions: none)

ERROR: No matching distribution found for apt-clone==0.2.1

The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1

This is my dockerfile contents (same as what is mentioned in the tutorial):

# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD [ "python3", "-m", "flask","run","--host=0.0.0.0" ]

It's not related to apt-clone==0.2.1 package. Whatever I try to install in the docker image, it fails. I tried apt update and installing pip3 in the dockerfile too but didn't work.

What did I miss?

4
  • try recreating the steps in your Dockerfile in interactive mode docker run -it --rm python:3.8-slim-buster. this has usually helped me (non-Py projects). let me know if you need elaborate instructions. it wouldn't fit in comments
    – kevinnls
    Commented Jun 2, 2021 at 4:47
  • @kevinnls Could you please elaborate your idea as an answer?
    – MeiH
    Commented Jun 2, 2021 at 5:07
  • He basically means docker run --rm -it python:3.8-slim-buster --name something bash and then manually docker cp requirements.txt something:/app etc to trace the steps of the Dockerfile.
    – tripleee
    Commented Jun 2, 2021 at 5:12
  • yes that ..... and go thru various troubleshooting steps. but we already have the answer :) cheers! 🎉
    – kevinnls
    Commented Jun 2, 2021 at 8:23

2 Answers 2

3

pip3 freeze outputs the package and its version installed in the current environment, no matter the package installed by pip or with other methods.

In fact, apt-clone==0.2.1 comes from debian package repo, not from pypi.org, see next:

$ pip3 freeze | grep apt-clone
$ apt-get install -y apt-clone
$ dpkg -l apt-clone
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  apt-clone      0.4.1        all          Script to create state bundles
$  dpkg -L apt-clone
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/apt-clone
/usr/share/doc/apt-clone/copyright
/usr/share/doc/apt-clone/changelog.gz
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/apt-clone.8.gz
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/apt_clone.py
/usr/lib/python3/dist-packages/apt_clone-0.2.1.egg-info
/usr/bin
/usr/bin/apt-clone
$ pip3 freeze | grep apt-clone
apt-clone==0.2.1

You could see from above, the apt_clone.py & apt_clone-0.2.1.egg-info are installed by debian package apt-clone, the 0.4.1 is just the debian package version, while 0.2.1 is the python package version.

So, for apt-clone similar, you need to install them with apt although they are seen in pip3 freeze.

5
  • From dpkg -L apt-clone we could see what apt-clone.deb be installed, /usr/lib/python3/dist-packages/apt_clone.py & /usr/lib/python3/dist-packages/apt_clone-0.2.1.egg-info means they are python packages.
    – atline
    Commented Jun 2, 2021 at 6:58
  • Yes as @tripleee pointed out, these are debian packages not the python packages, but apparently the point is that "pip freeze" is not a good tool for building a docker image.
    – MeiH
    Commented Jun 2, 2021 at 7:10
  • apt-clone.deb of course not python package, but when it be extracted to /usr/lib/python3/dist-packages, it becomes python package. You can verify it by delete /usr/lib/python3/dist-packages/apt_clone-0.2.1.egg-info, after delete the egg info, it nolonger be shown in pip3 freeze.
    – atline
    Commented Jun 2, 2021 at 7:22
  • 1
    Except don't mess with /usr/lib contents on a production system.
    – tripleee
    Commented Jun 2, 2021 at 7:23
  • 1
    The delete of egg-info is just to let you verify this is really a python package, as you thought it's not a python package in your comments. After confirm it's a python package, then you can understand why it be shown in pip freeze. But, YES, you shouldn't try to delete all egg-info as you even can't confirm which to delete or which not to delete. Still, the solution is: you need to know what package needed for your environment, and write your own requirements.txt.
    – atline
    Commented Jun 2, 2021 at 7:58
3

There is no package named apt-clone in the public PyPI repository, so pip3 obviously cannot find it.

If you actually have a Python package named like this, where did it come from?

  • If you created a package with this name locally, you need to install it too in your Docker image somehow.

  • If you are inside an organization, maybe you have a local PyPI with different packages than the public one, and then you need to configure pip3 to use it (try pip3 -i http://your.local.pypi/simple -r requirements.txt where obviously the URL needs to be something else, but we can't guess what).

If pip3 freeze says you have this package, it must have come from somewhere, but we don't know where. You have to figure that out, or supply more details to help us help you.

There is a Debian package named apt-clone but that obviously isn't something pip can install. Did you actually mean apt-get install -y apt-clone==0.2.1? (I can only find version 0.4.1 in Debian Buster, though.)

... @atline's answer explains what happened (you should probably accept that) but the simple fix is to manually populate requirements.txt with your actual requirements. pip3 freeze is a nice shorthand for that if you are in a virtual environment, but it's not a proper replacement for a manually curated requirements.txt or setup.py (or its modern replacements, currently moving from setup.cfg to pyproject.toml). If flask is the only package your app needs, simply put pip3 install flask and don't create a requirements.txt.

9
  • Thanks for the explanation. I didn't put apt-clone in the list, I just did a "pip3 freeze" to make the list and it listed apt-clone==0.2.1! As I mentioned if I remove this package, the same error exists with the next one too (like apturl==0.5.2) and so on
    – MeiH
    Commented Jun 2, 2021 at 5:06
  • Again, there is no public PyPI package named apturl but there is an Ubuntu package with that name. I can only speculate as to how pip freeze would come up with names of packages which are unknown to the external world, and have already done so in this answer. How did you build the environment where you ran pip3 freeze in the first place?
    – tripleee
    Commented Jun 2, 2021 at 5:09
  • Yes apparently there is a mismatch between packages I installed on my OS (mint 20) and the python packages, but I am wondering what should I do to resolve it! The only thing I did was the freeze command (exactly as the documentation which I referred to)
    – MeiH
    Commented Jun 2, 2021 at 6:50
  • Regarding the number of problematic packages I am wondering why the docker website didn't consider such situation.
    – MeiH
    Commented Jun 2, 2021 at 6:51
  • 1
    It should probably be clearer about it, but this is common practice.
    – tripleee
    Commented Jun 2, 2021 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.