# Simplifying Tcl/Tk detection

**URL:** <https://discuss.python.org/t/simplifying-tcl-tk-detection/14066>\
**Category:** Core Development\
**Tags:** build, stdlib\
**Created:** [March 4, 2022, 9:43pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066 "2022-03-04T21:43:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [March 4, 2022, 9:43pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/1 "2022-03-04T21:43:53Z")

</div>

**TL;DR** : simplify Tcl/Tk detection to `pkgconfig` and basic `autoconf` headers/libs checks.

### Background

@tiran and I have been rewriting stdlib extension module dependency detection in [bpo-45847](https://bugs.python.org/issue45847)\[1\] and [bpo-45573](https://bugs.python.org/issue45573)\[2\], partly sparked by Christian’s [bpo-45743](https://bugs.python.org/issue45743)\[3\].

### Proposal

I had a look a Ned’s comments in [bpo-34956](https://bugs.python.org/issue34956)\[4\] and related commits; IIUC, trying to use the macOS bundled Tcl/Tk is _not recommended_, so why then do we try so hard (in `setup.py`) to locate it? How about simplifying it to this:

- Replace `TCLTK_INCLUDES` with `TCLTK_CFLAGS` (for consistency)
- Keep the `--with-tcltk-*` options
- In `configure`:
  1. use pkgconfig to check for Tcl/Tk \>= 8.4.2 (we’ll have to loop over the various namings here: tcl, tcl8.6, tcl84, etc.)
  2. fall back to standard AC check headers/libs

- Reduce `detect_tkinter` in `setup.py` to one `addext()` line

`pkgconfig` should cover most \*nix systems. Mac users should use Homebrew::

```
$ PKG_CONFIG_PATH=$(brew --prefix tcl-tk)/lib/pkgconfig pkg-config --cflags --libs tcl tk
-I/usr/local/Cellar/tcl-tk/8.6.12_1/include -L/usr/local/Cellar/tcl-tk/8.6.12_1/lib -ltk8.6 -ltkstub8.6 -ltcl8.6 -ltclstub8.6

```

Thoughts? cc. @nad, @ronaldoussoren

* * *

1. Port module setup to `PY_STDLIB_MOD` macro and `addext()` 

2. Use pkg-config autoconf macros to detect flags for Modules/Setup 

3. Cleanup and simplify setup.py 

4. \_tkinter built on macOS 10.14 does not link to Tcl and Tk in /Library/Frameworks

---

<div class="post-metadata">

**Author:** ![nad](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nad/32/51_2.png) [@nad](https://discuss.python.org/u/nad)\
**Post date:** [March 4, 2022, 9:56pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/2 "2022-03-04T21:56:47Z")

</div>

We should deprecate the TCLTK\_\* variables and just rely on pkg-config. That works with MacPorts as well. Write up a PR and we can review it there.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [March 4, 2022, 9:58pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/3 "2022-03-04T21:58:38Z")

</div>

> [@nad](#):
>
> We should deprecate the TCLTK\_\* variables and just rely on pkg-config.

Even better. I’ve got a WIP branch from a couple of months ago. I’ll dig it up and create a PR.

---

<div class="post-metadata">

**Author:** ![tiran](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tiran/32/48_2.png) [@tiran](https://discuss.python.org/u/tiran)\
**Post date:** [March 4, 2022, 11:02pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/4 "2022-03-04T23:02:11Z")

</div>

Thank you! 👍

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [March 5, 2022, 4:43am UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/5 "2022-03-05T04:43:35Z")

</div>

We can drop support of 8.4, and maybe even 8.5.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [March 5, 2022, 7:45am UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/6 "2022-03-05T07:45:01Z")

</div>

> [@storchaka](#):
>
> We can drop support of 8.4, and maybe even 8.5.

Nice! I’ll create a separate bpo for that, though.

---

<div class="post-metadata">

**Author:** ![ronaldoussoren](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ronaldoussoren/32/61_2.png) [@ronaldoussoren](https://discuss.python.org/u/ronaldoussoren)\
**Post date:** [March 8, 2022, 10:52am UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/7 "2022-03-08T10:52:32Z")

</div>

Would the build continue to work without having pkg-config? The tool is not installed on macOS by default or through Xcode / Command Line Tools. Not everyone uses homebrew or macports.

---

<div class="post-metadata">

**Author:** ![tiran](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tiran/32/48_2.png) [@tiran](https://discuss.python.org/u/tiran)\
**Post date:** [March 8, 2022, 4:53pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/8 "2022-03-08T16:53:42Z")

</div>

You will be able to build Python without pkg-config, but some dependencies won’t be detected.

---

<div class="post-metadata">

**Author:** ![ronaldoussoren](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ronaldoussoren/32/61_2.png) [@ronaldoussoren](https://discuss.python.org/u/ronaldoussoren)\
**Post date:** [March 9, 2022, 7:46am UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/9 "2022-03-09T07:46:23Z")

</div>

I guess installing pkg-config isn’t too bad, one already has to install other libraries to get a full build (such as openssl).

BTW. I’m in favour of dropping support for the system install of Tcl/Tk, that library is ancient and broken. It is better to not have tkinter than one using the system version of Tk.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [March 13, 2022, 10:04pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/10 "2022-03-13T22:04:55Z")

</div>

> [@ronaldoussoren](#):
>
> BTW. I’m in favour of dropping support for the system install of Tcl/Tk, that library is ancient and broken. It is better to not have tkinter than one using the system version of Tk.

Great; I’ll keep the PR as it is, then.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [March 13, 2022, 10:06pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/11 "2022-03-13T22:06:45Z")

</div>

> [@erlendaasland](#):
>
> Great; I’ll keep the PR as it is, then.

FTR, I’m talking about [GH-31698](https://github.com/python/cpython/pull/31698)

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [March 15, 2022, 8:01am UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/12 "2022-03-15T08:01:20Z")

</div>

See also [Issue 46996: Drop support of Tcl/Tk older than 8.5.12 - Python tracker](https://bugs.python.org/issue46996).

---

<div class="post-metadata">

**Author:** ![barry](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/barry/32/42_2.png) [@barry](https://discuss.python.org/u/barry)\
**Post date:** [June 13, 2022, 6:54pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/13 "2022-06-13T18:54:37Z")

</div>

What’s the status of this for Python 3.11? I’ve been trying to test 3.11 from git w/TclTk but I can’t seem to reliably build locally with Brew installed packages.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [June 13, 2022, 7:53pm UTC](https://discuss.python.org/t/simplifying-tcl-tk-detection/14066/14 "2022-06-13T19:53:30Z")

</div>

GH-31698 was merged; `configure` now uses pkg-config to find Tcl/Tk.

The devguide was updated with new build instructions (earlier today). You can use this to build with Homebrew supplied Tcl/Tk:

```nohighlight
$ PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" ./configure

```
