#5025·hindsight

Windows: daemon via the #4466 base-interpreter trampoline skips venv .pth — import pywintypes fails on uv-managed venvs

Author: williamgbe-sketchCreated Oct 1, 2026Updated Oct 1, 2026

Summary

On Windows with a uv-managed venv, a daemon launched through the #4466 base-interpreter trampoline can't import pywintypes because the venv's site-packages .pth files are never processed.

Environment

  • Windows 10, uv-managed venv (pyvenv.cfg carries uv =)
  • hindsight_embed driving the local-embedded daemon

What happens

  1. DaemonEmbedManager._windows_gui_interpreter() finds venv/Scripts/pythonw.exe.
  2. That pythonw.exe is a uv trampoline (uv doesn't put a real interpreter in the venv Scripts dir — it CreateProcess's the base interpreter recorded in pyvenv.cfg).
  3. Per the #4466 fix, the code bypasses the trampoline and launches the base pythonw.exe with PYTHONPATH=<venv>/Lib/site-packages.
  4. A base interpreter given site-packages via PYTHONPATH does not process that directory's .pth files. So pywin32.pth (which adds pywin32_system32 via os.add_dll_directory/sys.path) is never applied.
  5. The daemon then fails on import pywintypes (e.g. through mcp/os/win32), aborting startup.

Observed

Daemon dead on start with ModuleNotFoundError/DLL-load failure for pywintypes; pywin32_system32 absent from the DLL search path.

Workaround (current)

A sitecustomize.py in the venv's site-packages that replicates pywin32.pth (adds win32, win32/lib, Pythonwin, pywin32_system32 to sys.path and os.add_dll_directory(...) for pywin32_system32). Base python auto-imports sitecustomize found via PYTHONPATH, so this works — but it's a per-venv manual patch that's lost on every venv rebuild.

Suggested fix

When the #4466 trampoline path hands the base interpreter the venv's site-packages via PYTHONPATH, also honor that directory's .pth entries for the child (e.g. ship a small .pth-replicating bootstrap the child can import), so pywin32_system32 lands on the DLL search path without a manual sitecustomize.py.