Docker Community Forums

Share and learn in the Docker community.

Why are there two python installations in the official python images?

Consider the following:

$ docker run --rm -it python bash
root@d1fea8455a6b:/# /usr/bin/python3 -c "from sys import path; print(path)"
['', '/usr/lib/', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages']
root@d1fea8455a6b:/# /usr/local/bin/python3 -c "from sys import path; print(path)"
['', '/usr/local/lib/', '/usr/local/lib/python3.9', '/usr/local/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/site-packages']

There are two different pythons installed, in /usr/bin/python3 and /usr/local/bin/python3, which look for their packages in two different directories (/usr/lib/... and /usr/local/lib/... respectively). This has caused a bug for me because I built an image based off of the python image, which installed a bunch of stuff in /usr/local/lib/, but it breaks if the user of my image accidentally uses the /usr/bin/python3 one.

I can work around this by getting rid of the /usr/bin/python3*, but why does this exist in the first place?

I found the answer in the Github Issues: apparently it’s an unavoidable side effect of the other packages that are included with the non-slim versions of python.