Open plog opened 3 days ago
Hi!
The python:latest
tag is currently an alias for 3.12.7-bookworm
. The 3.12.7-bookworm
image uses buildpack-deps:bookworm
as it's base:
https://github.com/docker-library/python/blob/4babb0e3da12a080e249f0d15c61404ac2e5d3b0/3.12/bookworm/Dockerfile#L7C6-L7C29
...and buildpack-deps:bookworm
like many other of the larger images includes a system Python installation:
$ docker run --rm -it buildpack-deps:bookworm bash -c 'which python3 && python3 --version'
/usr/bin/python3
Python 3.11.2
However, that system install won't be used by default, since the Python images put their own Python install ahead of the system install on PATH: https://github.com/docker-library/python/blob/24f7d17744c3bceceb3d60e86c81b2e15a8c3104/3.12/bookworm/Dockerfile#L9-L10
Which can be confirmed by running:
$ docker pull -q python:latest && docker run --rm -it python:latest bash
docker.io/library/python:latest
root@6b11c0285af3:/# which python3
/usr/local/bin/python3
root@6b11c0285af3:/# python3 -m site
sys.path = [
'/',
'/usr/local/lib/python312.zip',
'/usr/local/lib/python3.12',
'/usr/local/lib/python3.12/lib-dynload',
'/usr/local/lib/python3.12/site-packages',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python3.12/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
root@6b11c0285af3:/# pip install -q bleach
...
root@6b11c0285af3:/# pip show bleach
Name: bleach
Version: 6.1.0
...
Location: /usr/local/lib/python3.12/site-packages
...
If you are seeing something different, it means you have likely overridden PATH
and put the /usr/bin/
location ahead of /usr/local/bin
.
Fix the misconfigured PATH and the issue will go away.
Alternatively, switch to one of the slim Python images since they don't contain a system Python install:
$ docker pull -q python:3.12-slim && docker run --rm -it python:3.12-slim which -a python3
docker.io/library/python:3.12-slim
/usr/local/bin/python3
/usr/local/bin/python3
This is also documented here: https://hub.docker.com/_/python/#:~:text=Multiple%20Python%20versions%20in%20the%20image
I'm confused....
In some .py script
returns
Checking a random "pip (or pip3) install ...."