-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Packaging} enable site in python._pth instead of deleting it #33419
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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'. | ||||
| 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 | ||||
| ) | ||||
| ) | ||||
|
Comment on lines
+123
to
+127
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is nice to have a more general and robust logic. It's ok to keep your current logic. Nevertheless, the build script only downloads from a fixed URL
Simply appending Moreover, the glob may introduce an unnecessary attack surface. The glob |
||||
|
|
||||
| echo Installing pip | ||||
| curl --output get-pip.py %GET_PIP_DOWNLOAD_URL% | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
_pthfile is deleted?The
del python*._pthlogic was there since long ago as a manual process and was added tobuild.cmdin #21746 (comment).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is correct.
import siteis indeed the documented way of importing site packages.Actually,
python314._pthcontainsHowever, there may be deeper reason why
encodingscannot be imported.In my testing, with or without
python314._pthin the embedded Python folder, bothamd64andwin32Python can importencodingscorrectly:It may be related to pip's isolated BuildEnvironment.