Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions build_scripts/windows/scripts/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,21 @@ if not exist %PYTHON_DIR% (
del python-archive.zip
echo Python downloaded and extracted successfully

REM Delete _pth file so that Lib\site-packages is included in sys.path
REM Append `import site` to python*._pth so site.py runs at startup
REM (which adds Lib\site-packages to sys.path). We keep the file (rather
REM than deleting it) because on Python 3.14+ removing it breaks pip's
REM PEP 517 isolated BuildEnvironment subprocess: the child python.exe
REM can no longer locate the stdlib zip and dies in init_fs_encoding
REM with ModuleNotFoundError: No module named 'encodings'.
Comment on lines +115 to +118
Copy link
Copy Markdown
Member

@jiasli jiasli May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you find evidence that Python 3.14 specifically changed the behavior when _pth file is deleted?

The del python*._pth logic was there since long ago as a manual process and was added to build.cmd in #21746 (comment).

Copy link
Copy Markdown
Contributor Author

@YangAn-microsoft YangAn-microsoft May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there isn't a specific change introduced by Python 3.14 that caused the issue. In fact, only Python 3.14 win32 embedded has trouble importing from python*.zip.
I came up with this fix after experimenting the official way of enabling site packages for embedded python. (https://docs.python.org/3/using/windows.html#finding-modules)
Since this solves the win32 issue and using a more officially recommended solution than existing del python*._pth, I believe it's a proper change.

REM Keeping an explicit _pth makes stdlib + site-packages discoverable
REM in both the parent and any spawned subprocess.
REM https://github.com/pypa/pip/issues/4207#issuecomment-297396913
REM https://docs.python.org/3.10/using/windows.html#finding-modules
del python*._pth
REM https://docs.python.org/3/using/windows.html#finding-modules
if exist python*._pth (
for %%f in (python*._pth) do (
findstr /x "import site" "%%f" >nul || echo import site>> %%f
)
)

echo Installing pip
curl --output get-pip.py %GET_PIP_DOWNLOAD_URL%
Expand Down
Loading