This question is related to a documentation issue I opened on the Github tracker, which I filed mainly as a hack because I didn’t see the Discourse link initially.
To sum up: some Python installations do not include Tkinter, even though it is described in the documentation as something that should just be present automatically. There are a variety of reasons for this.
I know that there are OS-specific ways to install Tkinter into the “system Python” for Unix-like systems, and to update (“repair”) or replace Python installations (from the binary installer) on Windows to include Tkinter. Of course, if I add another, non-virtual installation of Python to my Linux system (say, in order to have an up-to-date version, while the system continues to rely on 3.8 for essential scripts that were tested on 3.8), I can choose to include Tkinter or not at installation time (especially if I am compiling from source). However, I would like to be able to change my mind later, and add Tkinter to a Python that doesn’t already have it.
I also know that a virtual environment created from a “base” that includes Tkinter, will have Tkinter; and one created from a base that does not, will not. I would like to be able to fix this later, and add Tkinter to virtual environments created from my system Python, without having to use the s-word (sudo
) and modify that Python.
I also know that there are not official PyPI packages to install Tkinter as if it were a third-party library, and furthermore that PyPI hosts many, deceptively named packages that look like they might resolve the issue, or at least help, but will not. (Notably, turtle
, which does not make it possible to use the turtle
standard library - but is instead an old, unmaintained, 2.x-only package for throttling HTTP requests.)
Is there any endorsed way to resolve this, and add Tkinter to an arbitrary Python installation that doesn’t already have it? Is there any good reason not to host a package on PyPI to accomplish this, or why it wouldn’t be possible? How about providing, say, some kind of bootstrap script, analogous to ensurepip
? Just how much trouble would I be getting myself into, if I tried to hack something (say, by trying to compile my own DLL/.so for _python
, and manually copying that and the appropriate .py
files into the right places)?