Cannot compile Anki anymore since recent macOS update (?)

When trying to run Anki from the console via ./tools/ts-run, I get the following error:

Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Repository pyqt6 instantiated at:
  /Users/henrikgiesel/Developer/Private/anki/WORKSPACE:14:11: in <toplevel>
  /Users/henrikgiesel/Developer/Private/anki/defs.bzl:43:17: in setup_deps
Repository rule install_pyqt defined at:
  /Users/henrikgiesel/Developer/Private/anki/python/pyqt/defs.bzl:22:31: in <toplevel>
ERROR: An error occurred during the fetch of repository 'pyqt6':
   Traceback (most recent call last):
	File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/defs.bzl", line 20, column 13, in _install_pyqt_impl
		fail("failed: %s (%s)" % (result.stdout, result.stderr))
Error in fail: failed: Collecting pyqt6==6.3.1
  Using cached PyQt6-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (11.7 MB)
Collecting pyqt6-qt6==6.3.1
  Using cached PyQt6_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (32.5 MB)
Collecting pyqt6-sip==13.4.0
  Using cached PyQt6_sip-13.4.0.tar.gz (111 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting pyqt6-webengine==6.3.1
  Using cached PyQt6_WebEngine-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (361 kB)
Collecting pyqt6-webengine-qt6==6.3.1
  Using cached PyQt6_WebEngine_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (83.9 MB)
Building wheels for collected packages: pyqt6-sip
  Building wheel for pyqt6-sip (PEP 517): started
  Building wheel for pyqt6-sip (PEP 517): finished with status 'error'
Failed to build pyqt6-sip
 (/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
  ERROR: Command errored out with exit status 1:
   command: /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/python /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/tmp_c7cpn06
       cwd: /private/var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/pip-install-6isaqxvq/pyqt6-sip_8ee9c6671f7c4197b41266088dd45533
  Complete output (12 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'PyQt6.sip' extension
  creating build
  creating build/temp.macosx-11.0-arm64-cpython-39
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -mmacosx-version-min=11.0 -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-undef-prefix -fPIC -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/ncursesw -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/uuid -Werror=unguarded-availability-new -I/install/include/python3.9 -c sip_array.c -o build/temp.macosx-11.0-arm64-cpython-39/sip_array.o
  sip_array.c:21:10: fatal error: 'Python.h' file not found
  #include <Python.h>
           ^~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pyqt6-sip
ERROR: Could not build wheels for pyqt6-sip which use PEP 517 and cannot be installed directly
Traceback (most recent call last):
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 87, in <module>
    main()
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 49, in main
    install_packages(requirements_file, base, [])
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 25, in install_packages
    assert not cmd.main(pip_args)
AssertionError
)
ERROR: /Users/henrikgiesel/Developer/Private/anki/WORKSPACE:14:11: fetching install_pyqt rule //external:pyqt6: Traceback (most recent call last):
	File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/defs.bzl", line 20, column 13, in _install_pyqt_impl
		fail("failed: %s (%s)" % (result.stdout, result.stderr))
Error in fail: failed: Collecting pyqt6==6.3.1
  Using cached PyQt6-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (11.7 MB)
Collecting pyqt6-qt6==6.3.1
  Using cached PyQt6_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (32.5 MB)
Collecting pyqt6-sip==13.4.0
  Using cached PyQt6_sip-13.4.0.tar.gz (111 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting pyqt6-webengine==6.3.1
  Using cached PyQt6_WebEngine-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (361 kB)
Collecting pyqt6-webengine-qt6==6.3.1
  Using cached PyQt6_WebEngine_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (83.9 MB)
Building wheels for collected packages: pyqt6-sip
  Building wheel for pyqt6-sip (PEP 517): started
  Building wheel for pyqt6-sip (PEP 517): finished with status 'error'
Failed to build pyqt6-sip
 (/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
  ERROR: Command errored out with exit status 1:
   command: /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/python /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/tmp_c7cpn06
       cwd: /private/var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/pip-install-6isaqxvq/pyqt6-sip_8ee9c6671f7c4197b41266088dd45533
  Complete output (12 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'PyQt6.sip' extension
  creating build
  creating build/temp.macosx-11.0-arm64-cpython-39
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -mmacosx-version-min=11.0 -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-undef-prefix -fPIC -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/ncursesw -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/uuid -Werror=unguarded-availability-new -I/install/include/python3.9 -c sip_array.c -o build/temp.macosx-11.0-arm64-cpython-39/sip_array.o
  sip_array.c:21:10: fatal error: 'Python.h' file not found
  #include <Python.h>
           ^~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pyqt6-sip
ERROR: Could not build wheels for pyqt6-sip which use PEP 517 and cannot be installed directly
Traceback (most recent call last):
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 87, in <module>
    main()
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 49, in main
    install_packages(requirements_file, base, [])
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 25, in install_packages
    assert not cmd.main(pip_args)
AssertionError
)
ERROR: /Users/henrikgiesel/Developer/Private/anki/qt/BUILD.bazel:123:10: //qt:runanki depends on @pyqt6//:pyqt6 in repository @pyqt6 which failed to fetch. no such package '@pyqt6//': failed: Collecting pyqt6==6.3.1
  Using cached PyQt6-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (11.7 MB)
Collecting pyqt6-qt6==6.3.1
  Using cached PyQt6_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (32.5 MB)
Collecting pyqt6-sip==13.4.0
  Using cached PyQt6_sip-13.4.0.tar.gz (111 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting pyqt6-webengine==6.3.1
  Using cached PyQt6_WebEngine-6.3.1-cp37-abi3-macosx_10_14_universal2.whl (361 kB)
Collecting pyqt6-webengine-qt6==6.3.1
  Using cached PyQt6_WebEngine_Qt6-6.3.1-py3-none-macosx_11_0_arm64.whl (83.9 MB)
Building wheels for collected packages: pyqt6-sip
  Building wheel for pyqt6-sip (PEP 517): started
  Building wheel for pyqt6-sip (PEP 517): finished with status 'error'
Failed to build pyqt6-sip
 (/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
/private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  warnings.warn(
  ERROR: Command errored out with exit status 1:
   command: /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/python /private/var/tmp/_bazel_henrikgiesel/b6d99a383a70ee71100c60d3110bcc7b/external/python/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/tmp_c7cpn06
       cwd: /private/var/folders/9r/c94mvk957530nbys8t2fly1h0000gn/T/pip-install-6isaqxvq/pyqt6-sip_8ee9c6671f7c4197b41266088dd45533
  Complete output (12 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'PyQt6.sip' extension
  creating build
  creating build/temp.macosx-11.0-arm64-cpython-39
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -mmacosx-version-min=11.0 -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-undef-prefix -fPIC -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/ncursesw -I/var/folders/c8/z52g4gc5679gygt8z0dx0jqm0000gn/T/tmpsrhf69ru/tools/deps/include/uuid -Werror=unguarded-availability-new -I/install/include/python3.9 -c sip_array.c -o build/temp.macosx-11.0-arm64-cpython-39/sip_array.o
  sip_array.c:21:10: fatal error: 'Python.h' file not found
  #include <Python.h>
           ^~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pyqt6-sip
ERROR: Could not build wheels for pyqt6-sip which use PEP 517 and cannot be installed directly
Traceback (most recent call last):
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 87, in <module>
    main()
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 49, in main
    install_packages(requirements_file, base, [])
  File "/Users/henrikgiesel/Developer/Private/anki/python/pyqt/install.py", line 25, in install_packages
    assert not cmd.main(pip_args)
AssertionError
)
ERROR: Analysis of target '//qt:runanki' failed; build aborted: Analysis failed
INFO: Elapsed time: 15.715s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (51 packages loaded, 168 targets configured)
FAILED: Build did NOT complete successfully (51 packages loaded, 168 targets configured)
    Fetching @local_config_cc; Running xcode-locator

I’ve tried the typical candidates (bazel clean --expunge, git clean -fdx, restart the system), but none helped. I think this error is raised ever since I updated to macOS 12.5, but I’m not quite sure there.

It’s not just a problem on recent main, I went back quite a few commits, to a time where I certainly was able to compile, and I get the same error now.

I’ve pushed a workaround.

Thanks, that fixed it.