Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 5 tasks
QuLogic opened this issue Apr 12, 2023 · 24 comments
Open
2 of 5 tasks
Assignees
Labels
bug Something isn't working

Comments

@QuLogic
Copy link

QuLogic commented Apr 12, 2023

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
  • macOS
  • Windows

Runner type:

  • 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 QuLogic added bug Something isn't working needs triage labels Apr 12, 2023
@QuLogic
Copy link
Author

QuLogic commented Apr 12, 2023

This is a similar issue to #402.

@marko-zivic-93
Copy link
Contributor

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 🙂

scito added a commit to scito/extract_otp_secrets that referenced this issue Apr 15, 2023
scito added a commit to scito/extract_otp_secrets that referenced this issue Apr 15, 2023
scito added a commit to scito/extract_otp_secrets that referenced this issue Apr 15, 2023
@damies13
Copy link

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.

@petercorke
Copy link

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.

@QuLogic
Copy link
Author

QuLogic commented Jun 15, 2023

@tacaswell
Copy link

@vitahoang
Copy link

vitahoang commented Jun 23, 2023

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 openssl@1.1)/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 openssl@1.1)/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 openssl@1.1)/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)

@albertosottile
Copy link

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.

@vitahoang
Copy link

vitahoang commented Jul 14, 2023

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.

@albertosottile
Copy link

Yes, I did. No change.

@vitahoang
Copy link

Yes, I did. No change.

Could you share your installation log?

@albertosottile
Copy link

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 openssl@1.1)/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 openssl@1.1)/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 openssl@1.1)/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 openssl@1.1 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$ 

@vitahoang
Copy link

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.

@albertosottile
Copy link

albertosottile commented Jul 14, 2023

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 openssl@1.1 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$ 

@vitahoang
Copy link

vitahoang commented Jul 14, 2023

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!

@albertosottile
Copy link

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...

@vitahoang
Copy link

I think that's the best workaround for now

@vitahoang
Copy link

damies13 added a commit to damies13/rfswarm that referenced this issue Jul 22, 2023
@damies13
Copy link

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 openssl@1.1)/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 openssl@1.1)/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 openssl@1.1)/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.

@carlosperate
Copy link

carlosperate commented Oct 3, 2023

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:

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

@MarcellPerger1
Copy link

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}}

@carlosperate
Copy link

In case this is useful to other people, as shown in #649 (comment) 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.

@priya-kinthali
Copy link
Contributor

Hello everyone👋,
Apologies for the delay in our response. The issue seems to be related to the location of the Tcl/Tk headers in the current binaries from the python-versions repository. Homebrew has updated the path, and the headers are now situated in subdirectories under /usr/local/opt/tcl-tk/include/tcl-tk.
Could you kindly provide the specific patch versions of Python that you are currently using and have been affected by this error? This will help us make the necessary changes and regenerate the specific version binaries?
Thank you!

@carlosperate
Copy link

I've re-run one of the failing tests I created last year (logs don't last that long) and it looks like it's still an issue in the latest patch releases for Python 3.6 to 3.10 (both included) for macOS 12 and 13:
https://github.com/carlosperate/pyinstaller-test/actions/runs/11854781198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants