fix: Force UTF-8 encoding for pip subprocess#2918
Merged
gaborbernat merged 2 commits intopypa:mainfrom Aug 1, 2025
Merged
Conversation
On non-UTF-8 systems, if your home directory contains non-ASCII characters, `pip download` can fail. This is because `virtualenv` expects the output of the `pip` subprocess to be UTF-8, but `pip` may default to a different encoding, causing a decoding error that results in `communicate()` returning `None` for the output streams. This change fixes the issue by explicitly setting `PYTHONIOENCODING=utf-8` in the environment for the `pip` subprocess. This ensures that `pip`'s output is always UTF-8, preventing the decoding error. A new test has been added to verify that the `PYTHONIOENCODING` environment variable is correctly set. Fixes pypa#2780 Signed-off-by: Emre Şafak <3928300+esafak@users.noreply.github.com>
Signed-off-by: Emre Şafak <3928300+esafak@users.noreply.github.com>
gaborbernat
approved these changes
Aug 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On non-UTF-8 systems, if your home directory contains non-ASCII characters,
pip downloadcan fail. This is becausevirtualenvexpects the output of thepipsubprocess to be UTF-8, butpipmay default to a different encoding, causing a decoding error that results incommunicate()returningNonefor the output streams.This change fixes the issue by explicitly setting
PYTHONIOENCODING=utf-8in the environment for thepipsubprocess. This ensures thatpip's output is always UTF-8, preventing the decoding error.A new test has been added to verify that the
PYTHONIOENCODINGenvironment variable is correctly set.Fixes #2780 #2338
tox -e fix)docs/changelogfolder