setup-python icon indicating copy to clipboard operation
setup-python copied to clipboard

Python 3.10.11 macOS: tk.h version (8.5) doesn't match libtk.a version (8.6)

Open QuLogic opened this issue 1 year ago • 22 comments

Description: Azure appears to be slowly rolling out image version 20230408.1. This seems to have hit our Python 3.10 jobs with the error:

RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)

This didn't affect the 3.9 job, which is also using the 20230408.1 image.

Action version: 0.214.0

Platform:

  • [ ] Ubuntu
  • [x] macOS
  • [ ] Windows

Runner type:

  • [x] Hosted
  • [ ] Self-hosted

Tools version: 3.10.11

Repro steps:
https://dev.azure.com/matplotlib/matplotlib/_build/results?buildId=32988&view=logs&j=de24e77b-0042-5832-9c98-cc3b6fa75eaf&t=6ee7601c-9c40-4d21-ae8c-c759c54cae95

Expected behavior: Tk works correctly.

Actual behavior: A runtime error is raised when attempting to import Tk:

RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)

QuLogic avatar Apr 12 '23 22:04 QuLogic

This is a similar issue to #402.

QuLogic avatar Apr 12 '23 22:04 QuLogic

Hello @QuLogic Thank you for creating this issue, we will take a look at it and come back to you as soon as we have some results 🙂

marko-zivic-93 avatar Apr 13 '23 13:04 marko-zivic-93

Just an FYI I'm encountering the same issue with my rfswarm builds, the issue seems to be specific to python 3.10 on MacOS

Not sure how helpful this is but I'll add it in case it helps find the cause:

OS Python Ver Test Result
ubuntu-latest 3.7 Pass
ubuntu-latest 3.8 Pass
ubuntu-latest 3.9 Pass
ubuntu-latest 3.10 Pass
ubuntu-latest 3.11 Pass
macos-latest 3.7 Pass
macos-latest 3.8 Pass
macos-latest 3.9 Pass
macos-latest 3.10 Fail
macos-latest 3.11 Pass
windows-latest 3.7 Pass
windows-latest 3.8 Pass
windows-latest 3.9 Pass
windows-latest 3.10 Pass
windows-latest 3.11 Pass

Here's my stack trace from stderr:

Traceback (most recent call last):
  File "/Users/runner/work/rfswarm/rfswarm/rfswarm_manager/rfswarm.py", line 6954, in <module>
    core = RFSwarmCore()
  File "/Users/runner/work/rfswarm/rfswarm/rfswarm_manager/rfswarm.py", line 2223, in __init__
    base.gui = RFSwarmGUI()
  File "/Users/runner/work/rfswarm/rfswarm/rfswarm_manager/rfswarm.py", line 3216, in __init__
    self.root = tk.Tk()
  File "/Users/runner/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/tkinter/__init__.py", line 2301, in __init__
    self._loadtk()
  File "/Users/runner/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/tkinter/__init__.py", line 2317, in _loadtk
    raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)"
RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)

A quick internet search for "RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)" brought me here.

Let me know if I can be of any more help?

Dave.

damies13 avatar Apr 27 '23 07:04 damies13

I'm seeing this also, Python 3.10 on macOS failing with a tk.h related error. I feel I've had this same thing a few years ago, maybe #402 mentioned above...

My last good build was 29 March, and the configuration was:

platform darwin -- Python 3.10.10, pytest-7.2.2, pluggy-1.0.0, matplotlib-3.7.1-cp310-cp310-macosx_10_12_x86_64.whl

Currently the configuration is:

platform darwin -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0, matplotlib-3.7.1-cp310-cp310-macosx_10_12_x86_64.whl

Some change to Python version, no change to Matplotlib.

petercorke avatar May 10 '23 10:05 petercorke

And now it's spread to Python 3.9: https://dev.azure.com/matplotlib/matplotlib/_build/results?buildId=34189&view=logs&j=d565cd3d-5b64-5d92-00ca-77c8c01737e7&t=44ca2d65-e117-5342-7366-f7ed442af407&l=416

Is there any progress? It's been 2 months now.

QuLogic avatar Jun 15 '23 22:06 QuLogic

It also seems to be affecting github actions: https://github.com/matplotlib/matplotlib/actions/runs/5326817190/jobs/9649372136?pr=26154#step:13:420

tacaswell avatar Jun 20 '23 22:06 tacaswell

Try this solution https://stackoverflow.com/a/60469203/8239990

# Install necessary system packages:
brew install tcl-tk openssl readline sqlite3 xz zlib
# Uninstall the current version
export PY_VER=$(python --version | cut -d " " -f 2)    
pyenv uninstall $(echo $PY_VER)
# Link the correct versions of Tcl/Tk
env LDFLAGS="-L$(brew --prefix [email protected])/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite3)/lib -L$(brew --prefix xz)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix tcl-tk)/lib" \
CPPFLAGS="-I$(brew --prefix [email protected])/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite3)/include -I$(brew --prefix xz)/include -I$(brew --prefix zlib)/include -I$(brew --prefix tcl-tk)/include" \
PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite3)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" \
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
pyenv install $(echo $PY_VER)

vitahoang avatar Jun 23 '23 17:06 vitahoang

Has anyone found a solution for this? I am currently unable to build any 3.8 version with proper tk support on macOS... I tried to use the environment tricks, but none of them works, pyenv still somehow picks the header from the system and not for homebrew.

albertosottile avatar Jul 14 '23 14:07 albertosottile

Has anyone found a solution for this? I am currently unable to build any 3.8 version with proper tk support on macOS... I tried to use the environment tricks, but none of them works, pyenv still somehow picks the header from the system and not for homebrew.

Have you try my suggestion above? I use it to successfully set up python 3.8 -> 3.11.

vitahoang avatar Jul 14 '23 14:07 vitahoang

Yes, I did. No change.

albertosottile avatar Jul 14 '23 14:07 albertosottile

Yes, I did. No change.

Could you share your installation log?

vitahoang avatar Jul 14 '23 14:07 vitahoang

This is for 3.8.12, but I tried all 3.8 minors from 12 to 17, same issue.

Albertos-iMac:~ alberto$ env LDFLAGS="-L$(brew --prefix [email protected])/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite3)/lib -L$(brew --prefix xz)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix tcl-tk)/lib" CPPFLAGS="-I$(brew --prefix [email protected])/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite3)/include -I$(brew --prefix xz)/include -I$(brew --prefix zlib)/include -I$(brew --prefix tcl-tk)/include" PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite3)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" pyenv install 3.8.12
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.12.tar.xz...
-> https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tar.xz
Installing Python-3.8.12...
patching file 'Misc/NEWS.d/next/Build/2021-10-11-16-27-38.bpo-45405.iSfdW5.rst'
patching file configure
patching file configure.ac
python-build: use tcl-tk from $PYTHON_CONFIGURE_OPTS
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
nInstalled Python-3.8.12 to /Users/alberto/.pyenv/versions/3.8.12
Albertos-iMac:~ alberto$ pyenv shell 3.8.12
Albertos-iMac:~ alberto$ idle
Traceback (most recent call last):
  File "/Users/alberto/.pyenv/versions/3.8.12/bin/idle", line 5, in <module>
    main()
  File "/Users/alberto/.pyenv/versions/3.8.12/lib/python3.8/idlelib/pyshell.py", line 1483, in main
    root = Tk(className="Idle")
  File "/Users/alberto/.pyenv/versions/3.8.12/lib/python3.8/tkinter/__init__.py", line 2272, in __init__
    self._loadtk()
  File "/Users/alberto/.pyenv/versions/3.8.12/lib/python3.8/tkinter/__init__.py", line 2288, in _loadtk
    raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)"
RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)
Albertos-iMac:~ alberto$ 

albertosottile avatar Jul 14 '23 14:07 albertosottile

I tried reinstalling Python versions with this trick but only >= python 3.11 works. Could you try on your env? if works, maybe you should upgrade the python version.

vitahoang avatar Jul 14 '23 15:07 vitahoang

I wish I could, but I need 3.8 for https://github.com/diStyApps/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI ... Do you remember which minor of 3.8 you were able to install with the trick?

EDIT: as a matter of fact 3.11.4 does not require any env trick...

Albertos-iMac:~ alberto$ pyenv install 3.11
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.4.tar.xz...
-> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
Installing Python-3.11.4...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.11.4 to /Users/alberto/.pyenv/versions/3.11.4
Albertos-iMac:~ alberto$ pyenv shell 3.11.4
Albertos-iMac:~ alberto$ idle
Albertos-iMac:~ alberto$ 

albertosottile avatar Jul 14 '23 16:07 albertosottile

I tried reinstalling Python versions with this trick but only >= python 3.11 works. Could you try on your env? if works, maybe you should upgrade the python version.

I just use poetry to install this repo's dependency on Python 3.11. It works!

vitahoang avatar Jul 14 '23 16:07 vitahoang

I just use poetry to install this repo's dependency on Python 3.11. It works!

Yes, I just did the same, it took a while as I had to build wheels for pandas. Anyway, this does not really solve the issue...

albertosottile avatar Jul 14 '23 16:07 albertosottile

I think that's the best workaround for now

vitahoang avatar Jul 14 '23 17:07 vitahoang

Just found this, it might shed some light on the issue:

https://github.com/python/devguide/pull/1058#issuecomment-1479229149

https://docs.brew.sh/How-to-Build-Software-Outside-Homebrew-with-Homebrew-keg-only-Dependencies#what-does-keg-only-mean

vitahoang avatar Jul 14 '23 17:07 vitahoang

I tried adding the following to my github workflow:

      # https://github.com/actions/setup-python/issues/649
      - name: "MacOS Installs"
        if: ${{ matrix.platform == 'macos-latest' && matrix.python <= 3.11 }}
        run: |
          # Install necessary system packages:
          brew install pyenv
          brew install tcl-tk openssl readline sqlite3 xz zlib
          # Uninstall the current version
          export PY_VER=$(python --version | cut -d " " -f 2)
          pyenv uninstall $(echo $PY_VER)
          # Link the correct versions of Tcl/Tk
          env LDFLAGS="-L$(brew --prefix [email protected])/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite3)/lib -L$(brew --prefix xz)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix tcl-tk)/lib" \
          CPPFLAGS="-I$(brew --prefix [email protected])/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite3)/include -I$(brew --prefix xz)/include -I$(brew --prefix zlib)/include -I$(brew --prefix tcl-tk)/include" \
          PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite3)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" \
          PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
          pyenv install $(echo $PY_VER)

It fails at pyenv uninstall $(echo $PY_VER) with

pyenv: version `3.10.12' not installed Error: Process completed with exit code 1.

i also tried this but got a similar result

          pyenv uninstall ${{ matrix.python }}

Unless I can get the workaround working I won't merge it into my release branches, so for now most of my MacOS builds are still failing. but I now have a branch I can use to test various workarounds for this issue. Can anyone guide me where I want wrong with this workaround?

As previously noted by @petercorke the original issue is impacting python 3.10, I have found it's actually now impacting python versions 3.7, 3.8, 3.9 and 3.10 (basically everything below 3.11 which is a degradation from earlier when it was only impacting version 3.9.

Dave.

damies13 avatar Jul 22 '23 12:07 damies13

This is still a problem on all macOS images (macos-11, macos-12, macos-13) with Python 3.7, 3.8 and 3.9 at least (not tested newer releases). 3.7 might be end-of-life, but 3.8 and 3.9 should still be supported.

Edit: I've run a simple tk test and this is the current status:

  • https://github.com/carlosperate/pyinstaller-test/actions/runs/6394336373
  • https://github.com/carlosperate/pyinstaller-test/blob/062ad84142f3def4abfa829c73b8935b7bd0ec96/.github/workflows/tk.yml
Python 3.7 Python 3.8 Python 3.9 Python 3.10 Python 3.11 Python 3.12
macOS 11
macOS 12
macOS 13

So basically anything lower than Python 3.11 still fails

carlosperate avatar Oct 03 '23 14:10 carlosperate

Unless I can get the workaround working I won't merge it into my release branches, so for now most of my MacOS builds are still failing. but I now have a branch I can use to test various workarounds for this issue. Can anyone guide me where I want wrong with this workaround?

Not sure if you're still interested in a workaround, but for github actions, I found that installing python using pyenv (without running setup-python at all) fixed the issue. For example,

    steps:
    - uses: actions/checkout@v3
    - name: (MacOS, <3.11) Fix Python's tkinter
      shell: bash
      if: ${{ startswith(matrix.os, 'macos-') && contains('3.9;3.10', matrix.python-version) }}
      run: |
        brew install tcl-tk pyenv openssl readline sqlite3 xz zlib
        env \
          PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
          LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
          CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
          PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
          CFLAGS="-I$(brew --prefix tcl-tk)/include" \
          PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
          pyenv install ${{matrix.python-version}}
        pyenv global ${{matrix.python-version}}

MarcellPerger1 avatar Jan 21 '24 21:01 MarcellPerger1

In case this is useful to other people, as shown in https://github.com/actions/setup-python/issues/649#issuecomment-1745056485 the default macOS Python 3.7, 3.8, 3.9, 3.10 versions don't work with Tkinter, but older releases do, so I'm currently using: 3.7.15, 3.8.15, 3.9.15, 3.10.10.

carlosperate avatar Jan 22 '24 11:01 carlosperate