Skip to content

Load the release CPython in Windows Debug builds - #261

Merged
FeodorFitsner merged 11 commits into
mainfrom
fix/windows-debug-builds-release-python
Oct 29, 2026
Merged

FeodorFitsner merged 11 commits into
mainfrom
fix/windows-debug-builds-release-python

Conversation

@ndonkoHenri

@ndonkoHenri ndonkoHenri commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Reported in flet-dev/flet#7022: flet test on Windows fails with ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'.

Cause

Debug Windows builds (flutter test, flutter run, and Flet's flet test and flet debug windows) bundle a debug build of CPython: python3XY_d.dll and python3_d.dll, loaded through dart_bridge_d.dll. A debug CPython only imports extension modules named *_d.pyd:

importlib.machinery.EXTENSION_SUFFIXES == ['_d.cp314-win_amd64.pyd', '_d.pyd']

PyPI wheels only ship the release .pyd (_pydantic_core.cp314-win_amd64.pyd), so every package with compiled code (pydantic-core, numpy, cryptography, …) fails to import in Debug builds, even though its .pyd is installed. Release builds (flet build windows) aren't affected.

The debug variant comes from the original Windows support, when the plugin itself included Python.h and MSVC Debug builds had to link python3X_d.lib. Since 3.0.0 (#209), only dart_bridge touches Python, through FFI, so nothing needs the debug CPython any more.

#260 doesn't change this: it only removes CPython's debug modules from Release and Profile builds.

Changes

  1. Load the release CPython in Debug builds. CMakeLists.txt bundles python3XY.dll, python3.dll and dart_bridge.dll in every configuration and stops downloading dart_bridge_d.dll. dart_bridge_ffi.dart always opens dart_bridge.dll. A Debug runner loads the release DLLs as they are: nothing it builds links Python, and the CRTs stay inside their own DLLs.
  2. Drop CPython's *_d modules from Debug builds too. Nothing imports them now, so the *_d.* cleanup from Bump to 6.1.1: Release Windows apps drop Python's debug modules again #260 runs in every configuration.
  3. Changelog entries under 6.1.2 for serious_python, serious_python_windows and serious_python_platform_interface. Versions aren't bumped.

Testing

On Windows 11 (x64 Flutter 3.47.7), a Flet 1.1.0 project built from source (flet-1.1.0 at e660c80) that depends on pydantic, run with flet test:

serious_python Python in the test app Result
Baseline 6.1.0 (pinned by Flet 1.1.0) python314_d.dll + dart_bridge_d.dll, EXTENSION_SUFFIXES == ['_d.cp314-win_amd64.pyd', '_d.pyd'] ModuleNotFoundError: No module named 'pydantic_core._pydantic_core', test fails
This PR (ed45d2c, via dependency_overrides) 6.1.1 + this branch python314.dll + dart_bridge.dll 1 passed

With a clean Debug output folder, the build bundles only dart_bridge.dll, python3.dll and python314.dll next to the exe, and DLLs\ has no *_d.* files.

The same changes applied to serious_python 5.0.0 also fix a Flet 1.0.5 project.

Not tested: flet debug windows, which builds through the same Debug path.

The trade-off is that a Debug Flutter build can no longer step into CPython's own C code, which Flet apps don't need.

Follow-ups (other repos)

  • Flet's Windows runner template (windows/runner/main.cpp) falls back to dart_bridge_d.dll when dart_bridge.dll is missing. With this change that branch is never taken; it can go when Flet bumps to this release.
  • dart-bridge can stop building dart_bridge_d-windows-x86_64.dll once no serious_python release downloads it.

Debug Windows builds (flutter test, flutter run) bundled a debug build of
CPython (python3XY_d.dll, loaded through dart_bridge_d.dll). A debug CPython
only imports extension modules named *_d.pyd, which PyPI wheels don't ship,
so every compiled package (pydantic-core, numpy, ...) failed with
ModuleNotFoundError although its .pyd was installed.

The debug variant dates from when the plugin itself compiled against
Python.h. Since 3.0.0 only dart_bridge touches Python, through FFI, so every
build configuration now bundles python3XY.dll, python3.dll and
dart_bridge.dll, and the Dart side always opens dart_bridge.dll.
Every build configuration loads the release CPython now, so nothing imports
the *_d.pyd, *_d.dll and *_d.pdb files in DLLs/. Remove them from Debug
builds as well, not only from Release and Profile builds.
@FeodorFitsner
FeodorFitsner merged commit 7a41fcd into main Oct 29, 2026
55 of 58 checks passed
@FeodorFitsner
FeodorFitsner deleted the fix/windows-debug-builds-release-python branch October 29, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants