From 810385b971bc101182ded21e83457d83790e413a Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 6 Aug 2020 11:45:29 +0800 Subject: [PATCH] Always use UTF-8 to read pyvenv.cfg --- news/8717.bugfix | 1 + src/pip/_internal/utils/virtualenv.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 news/8717.bugfix diff --git a/news/8717.bugfix b/news/8717.bugfix new file mode 100644 index 00000000000..e8c8533c492 --- /dev/null +++ b/news/8717.bugfix @@ -0,0 +1 @@ +Always use UTF-8 to read ``pyvenv.cfg`` to match the built-in ``venv``. diff --git a/src/pip/_internal/utils/virtualenv.py b/src/pip/_internal/utils/virtualenv.py index 596a69a7dad..4a7812873b3 100644 --- a/src/pip/_internal/utils/virtualenv.py +++ b/src/pip/_internal/utils/virtualenv.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import io import logging import os import re @@ -51,7 +52,9 @@ def _get_pyvenv_cfg_lines(): """ pyvenv_cfg_file = os.path.join(sys.prefix, 'pyvenv.cfg') try: - with open(pyvenv_cfg_file) as f: + # Although PEP 405 does not specify, the built-in venv module always + # writes with UTF-8. (pypa/pip#8717) + with io.open(pyvenv_cfg_file, encoding='utf-8') as f: return f.read().splitlines() # avoids trailing newlines except IOError: return None