I am running Linux Mint 20.3 Cinnamon, and I have some virtual environments created (using the standard library venv module) from the system Python (no other Python installations), which is version 3.8.10. I know that the system Python was configured without TKinter support:
>>> import _tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '_tkinter'
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tkinter'
>>> import turtle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/turtle.py", line 107, in <module>
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
Curiously, the turtle module is present (and fails to import because tkinter is missing) even though tkinter is not (and would fail to import because _tkinter is missing).
I understand that I should be able to make TKinter available globally by installing the python3-tk system package; and I understand that TKinter depends on non-Python code that needs to be installed anyway (and not on a per-venv basis).
However: to my understanding, installing python3-tk will, as well as installing the relevant TCL/Tk code, update the system Python to include the tkinter standard library package. On principle, I would like to avoid this. I infer that the absence of this package is a deliberate choice by the Mint team (especially considering that it is even absent in Cinnamon) with positive security implications (a rogue Python script would not be able to exploit a hypothetical Tcl/Tk vulnerability discovered in the future, except within a user-level venv).
It does appear that my system already has that TCL code installed, anyway:
$ apt list tcl
Listing... Done
tcl/focal,now 8.6.9+1 amd64 [installed]
tcl/focal 8.6.9+1 i386
Is it possible to configure my system such that
- the core TCL/Tk code is available and usable from Python virtual environments;
- each new virtualenv that I create can get Python bindings (i.e., the
tkinterstandard library package) to that code from some standard source; but - the system Python is not modified (and fails-by-design to run Tkinter GUI code)?
If so, how?
And what exactly does python3-tk propose to install, anyway?