docker-library / python

Docker Official Image packaging for Python
https://www.python.org/
MIT License
2.54k stars 1.07k forks source link

Python 3.9 image has symlinks point at Python 3.11 #844

Closed rafaelcpalmeida closed 1 year ago

rafaelcpalmeida commented 1 year ago

I've recently noticed that the newest changes introduced on python:3.9 are breaking the /usr/bin/python3 symlink pointing it to python3.11 instead of python3.9

A python:3.9 image freshly pulled from DockerHub: image

A python:3.9 image I had on another machine pulled some time ago: image

Looking at DockerHub it seems that this layer is introducing Python 3.11: image

Tell me if there's anything else I would need to add to this issue.

yosifkit commented 1 year ago

This is the same as: https://github.com/docker-library/python/issues/174 https://github.com/docker-library/python/issues/345 https://github.com/docker-library/python/issues/486, but in this case the one from Debian is newer than the one we add to /usr/local/

See also the blurb on the Docker Hub docs: https://github.com/docker-library/docs/tree/883d8e242e5cdb1a95c6d530d49b76631a6af030/python#multiple-python-versions-in-the-image

tianon commented 1 year ago

To put that another way, if you've been using /usr/bin/python3, you might as well switch to using raw buildpack-deps or even FROM debian because you haven't been running the Python build provided by this image. :sweat_smile:

rafaelcpalmeida commented 1 year ago

I see 🤔 Using python:3.9-slim I'm still getting Python 3.11, is this intentional? Per https://github.com/docker-library/docs/tree/883d8e242e5cdb1a95c6d530d49b76631a6af030/python#multiple-python-versions-in-the-image I assumed it shouldn't happen.

image
yosifkit commented 1 year ago

Using python:3.9-slim (or any of the python images), you need to use /usr/local/bin/python3, /usr/bin/env python3 or just plain python3 if you want the Python we compile in the image. If you use the full path to the Debian python, then you will get the Debian python version. We don't replace/override that because it could break system packages.

If /usr/bin/python3 (Debian python) exists in the slim image, then it means you installed a Debian package that required it.

$ docker run -it --rm python:3.9-slim bash
Unable to find image 'python:3.9-slim' locally
3.9-slim: Pulling from library/python
5b5fe70539cd: Already exists
f4b0e4004dc0: Pull complete
ec1650096fae: Pull complete
2ee3c5a347ae: Pull complete
d854e82593a7: Pull complete
Digest: sha256:0074c6241f2ff175532c72fb0fb37264e8a1ac68f9790f9ee6da7e9fdfb67a0e
Status: Downloaded newer image for python:3.9-slim
root@dbad579b3cc2:/# /usr/local/bin/python3 --version
Python 3.9.17
root@dbad579b3cc2:/# /usr/bin/env python3 --version
Python 3.9.17
root@dbad579b3cc2:/# python3 --version
Python 3.9.17
root@dbad579b3cc2:/# /usr/bin/python3
bash: /usr/bin/python3: No such file or directory
rafaelcpalmeida commented 1 year ago

That makes sense to me. Appreciate the time you took to explain it! I'll then close this as it doesn't make sense to keep it open.

tianon commented 1 year ago

While re-reading our description with the fresh eyes you've provided (especially the Debian Python now in the rare case of being newer than many of ours), I've put up https://github.com/docker-library/docs/pull/2344 to hopefully clarify this better. :bow: :heart:

rafaelcpalmeida commented 1 year ago

That's more clear now! Thank you for the time you took to explain it and for your attention! 🙇🏽‍♂️