How to configure Python for Tcl 9.0 on Ubuntu?

I use my old Dell laptop (running KUbuntu 26.04 LTS & X11 instead of Wayland) almost entirely to build and test Python from GitHub. This morning, I got an error for test_tkinter. Running that in isolation, I noticed that several tests were skipped because Tcl/Tk >= 8.7 wasn’t installed. apt told me I had Tcl/Tk 9.0 available, but nothing later than the 8.6 release in the 8.x series. (8.6 seems to be required for the KUbuntu desktop.) I installed the 9.0 bits:

$ apt search tcl | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

deja-dup/resolute,now 50.0-3 amd64 [installed,automatic]
libgedit-gtksourceview-300-common/resolute,now 299.5.0-4 all [installed,automatic]
libtcl8.6/resolute,now 8.6.17+dfsg-1build1 amd64 [installed,automatic]
libtcl9.0/resolute,now 9.0.3+dfsg-1 amd64 [installed,automatic]
libtk8.6/resolute,now 8.6.17-1build1 amd64 [installed,automatic]
libtk9.0/resolute,now 9.0.3-1 amd64 [installed,automatic]
tcl/resolute,now 8.6.16build1 amd64 [installed,automatic]
tcl8.6/resolute,now 8.6.17+dfsg-1build1 amd64 [installed,automatic]
tcl9.0/resolute,now 9.0.3+dfsg-1 amd64 [installed,automatic]
tcl9.0-dev/resolute,now 9.0.3+dfsg-1 amd64 [installed]
tk/resolute,now 8.6.16build1 amd64 [installed,automatic]
tk8.6/resolute,now 8.6.17-1build1 amd64 [installed,automatic]
tk9.0/resolute,now 9.0.3-1 amd64 [installed,automatic]
tk9.0-dev/resolute,now 9.0.3-1 amd64 [installed]
yt-dlp/resolute,now 2026.03.17-1 all [installed,automatic]

but configure tells me tcl.h wasn’t found, though there is one in the Tcl 9.0 install:

$ sudo find / -name tcl.h 2>/dev/null
/usr/include/tcl9.0/tcl-private/generic/tcl.h
/usr/include/tcl9.0/tcl.h

pkg-config shows me the necessary 9.0 bits seem to be available:

$ pkg-config --list-all | egrep 'tcl|tk'
tk9.0                          The Tk Toolkit - Tk is a cross-platform graphical user interface toolkit, the standard GUI not only for Tcl, but for many other dynamic languages as well.
tcl9.0                         Tool Command Language - Tcl is a powerful, easy-to-learn dynamic programming language, suitable for a wide range of uses.

It seems configure doesn’t know about Tcl/Tk 9.0 yet. In fact, though some tests require Tcl/Tk >= 8.7, it seems configure doesn’t even check for that. From configure.ac:

dnl Detect Tcl/Tk. Use pkg-config if available.
dnl
found_tcltk=no
for _QUERY in \
  "tcl >= 8.5.12 tk >= 8.5.12" \
  "tcl8.6 tk8.6" \
  "tcl86 tk86" \
  "tcl8.5 >= 8.5.12 tk8.5 >= 8.5.12" \
  "tcl85 >= 8.5.12 tk85 >= 8.5.12" \
; do
  PKG_CHECK_EXISTS([$_QUERY], [
    PKG_CHECK_MODULES([TCLTK], [$_QUERY], [found_tcltk=yes], [found_tcltk=no])
  ])
  AS_VAR_IF([found_tcltk], [yes], [break])
done

Am I missing something obvious? Is there a way to build Python on Ubuntu variants using Tcl/Tk 9.0?

There is, I believe, an 8.7.0beta, but 8.7.0 was cancelled in favor of 9.0.0. More bang for the buck, I presume. S. Storchaka has been busy the last month upgrading tkinter to fully support 9.0+, including the future 9.1 (now in alpha or beta). Unless you build CPython yourself from current source, you will need the next release of 3.13+ to get all the bug fixes. I can imagine that other tk users are behind on this, but I would not expect the tk KUbuntu uses to affect running the tkinter tests.

@storchaka Do you know anything about sucessfully running tk9 on Ubuntu?

Thanks. Yes, I’m building from the current repo on the main branch. I guess it’s to be expected that if the code or tests are undergoing change currently, there are likely to be some config and test differences across platforms. I’ll leave off there and let Serhiy do his thing…

FWIW, after removing all traces of Tcl/Tk 9.0 and making sure the necessary Tcl/Tk 8.6 bits were actually installed, I failed to get the test failure which sent me down this particular rabbit hole. I have now climbed out of that hole.

I always built non-default Tcl/Tk from sources. I was surprised to find that Tcl/Tk 9.0 are available (but not installed as preferred) on my Kubuntu.

configure only probes the unversioned Tcl/Tk, so you must pass the flags explicitly.

./configure --with-pydebug \
  TCLTK_CFLAGS="-I/usr/include/tcl9.0 -I/usr/include/tcl9.0/tcl-private/libtommath -DTCL_WITH_EXTERNAL_TOMMATH" \
  TCLTK_LIBS="-L/usr/lib/x86_64-linux-gnu -ltcl9tk9.0 -ltcl9.0"

Cool, thanks, Serhiy.

It looks to me like there’s actually a Ubuntu packaging bug here if anyone wants to report it :slight_smile: . It looks like the tcl9.0-dev and tk9.0-dev packages do install t{cl,k}9.0.pc files, but those files don’t satisfy the check for tcl > 8.5.12 and tk > 8.5.12 because they’re actually tcl9.0 and tk9.0 rather than tcl and tk. Adding explicit tcl9.0/tk9.0 entries to the for _QUERY in allows tcl9.0 to be found, but tk9.0 then looks for and can’t find tcl (no 9.0). That is, Ubuntu seems to be patching Tcl/Tk to rename the .pc files, but not patching the content of the tk9.0.pc to look for tcl9.0 rather than tcl.