Skip to content

Use UTF-8 for log file. #10071

@methane

Description

@methane

What's the problem this feature will solve?

  • If default text encoding is not UTF-8 (e.g. Windows users), pip might fail to log non-ASCII texts (e.g. non-ASCII paths on Windows).
  • When using PYTHONWARNDEFAULTENCODING=1 (Python 3.10), dictConfg() emit EncodingWarning:
/home/inada-n/pyenv/versions/3.10.0b2/lib/python3.10/logging/config.py:748: EncodingWarning: 'encoding' argument not specified
  result = factory(**kwargs)

Describe the solution you'd like

diff --git a/src/pip/_internal/utils/logging.py b/src/pip/_internal/utils/logging.py
index 0569b9248..39a18fd6c 100644
--- a/src/pip/_internal/utils/logging.py
+++ b/src/pip/_internal/utils/logging.py
@@ -375,6 +375,7 @@ def setup_logging(verbosity, no_color, user_log_file):
                     "level": "DEBUG",
                     "class": handler_classes["file"],
                     "filename": additional_log_file,
+                    "encoding": "utf-8",
                     "delay": True,
                     "formatter": "indent_with_timestamp",

Alternative Solutions

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions