python / cpython

The Python programming language
https://www.python.org
Other
62.72k stars 30.07k forks source link

Add tkinter to the official embeddable python zip file #99566

Open martinResearch opened 1 year ago

martinResearch commented 1 year ago

Feature

Add tkinter to the official embeddable python zip file

Pitch

At the moment tkinter is not included to the official embeddable python zip file despite being part of the standard library. Unfortunately, there does not seem to be an easy way to add it back after installing/unzipping the embeddable python because it is not on pypi.org. It seems that adding tkinter to the zip file could be simply a matter of adding a single line in https://github.com/python/cpython/blob/0faa0ba240e815614e5a2900e48007acac41b214/PC/layout/support/options.py If the omission has been motivated by trying to keep the nugget file as small as possible maybe an alternative would be to provide an official tkinter package on pypi.org or to provide two embeddable versions.

zooba commented 1 year ago

This is deliberate, and certainly won't be added to the default. The vast majority of uses I'm aware of for the embeddable runtime do not use Tkinter, and it would be wasteful bloat to include all of the files in there.

I also think having a second embeddable package would cause even more confusion than having a single one.

Publishing to PyPI would be fine by me, though since _tkinter is written with the assumption that it'll match a particular runtime version, it would be quite a change of policy there. @terryjreedy cares for that area of things most.

Alternatively, if you do a regular install, you can just copy Lib\tkinter, the relevant files from DLLs and tcltk into your copy of the embeddable distro and they should be just fine. You might need to configure search paths for Tcl in your host app.

martinResearch commented 1 year ago

I understand the size constraint on the embeddable version is important and would like to understand why we would have a similar constraint on the nuget package. In the documentation it is said "The nuget.org package is a reduced size Python environment intended for use on continuous integration and build systems that do not have a system-wide install of Python." How important is the "reduced size" goal? adding tkinter to the nuget would increase its size by about 4Mo to the nuget file bringing the total size to about 20Mo. Going from 16Mo to 20Mo does not necessarily seems like a huge problem if the goal is to use it in continuous integration and build systems in case one installs other python libraries afterward which probably take much more than 4Mo, is that not generally the case? Unfortunately, the suggested workaround consisting in using a regular install and then copy Lib\tkinter does not seem like easily doable in the scenario envisioned for the nuget use described in the documentation by "build systems that do not have a system-wide install of Python". Hopefully a way to get an official tkinter package from pypi.org could be put in place.

zooba commented 1 year ago

The concern isn't just the package size, but the surface area. Tcl/Tk adds a vast amount of surface area, that has huge implications for security and compatibility (though we generally don't update them often enough to cause compatibility problems...).

Getting them onto PyPI so that only people using it pay that price (and also have a way to help themselves avoid issues) would be much more preferable. We don't do anything special, so anyone could publish a build - it doesn't have to be "official" to fill the gap.