Skip to content

Conversation

@esafak
Copy link
Contributor

@esafak esafak commented Jul 31, 2025

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 #2780 #2338

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

google-labs-jules bot and others added 2 commits July 31, 2025 18:39
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 gaborbernat merged commit 01074bc into pypa:main Aug 1, 2025
42 checks passed
@esafak esafak deleted the fix/pip-encoding-issue-2780 branch August 1, 2025 00:07
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.

Calling pip download on non-utf system can fail if user home folder has non ASCII chars

2 participants