Windows 10 执行pip list报错 UnicodeDecodeError: 'gbk' codec can't decode

在命令行执行任何pip命令都报错:

C:\Users\hyang0>pip --version
Traceback (most recent call last):
  File "c:\python3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\python3\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "c:\python3\lib\site-packages\pip\__init__.py", line 219, in main
    cmd_name, cmd_args = parseopts(args)
  File "c:\python3\lib\site-packages\pip\__init__.py", line 159, in parseopts
    parser = create_main_parser()
  File "c:\python3\lib\site-packages\pip\__init__.py", line 137, in create_main_parser
    parser = ConfigOptionParser(**parser_kw)
  File "c:\python3\lib\site-packages\pip\baseparser.py", line 148, in __init__
    self.config.read(self.files)
  File "c:\python3\lib\configparser.py", line 697, in read
    self._read(fp, filename)
  File "c:\python3\lib\configparser.py", line 1015, in _read
    for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 67: illegal multibyte sequence

在segmentfault][1]上找到问题原因,之前配置过 %APPDATA%\pip\pip.ini 文件,编码为utf-8。估计要用原生的cp939才行,将pip.ini删掉后重新执行pip命令恢复正常。

C:\Users\hyang0>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (28.8.0)
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\hyang0>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 876kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-10.0.1

C:\Users\hyang0>
[1]: https://segmentfault.com/q/1010000012807558/a-1020000012989591 "pip gbk decode"

posted on 2018-07-11 10:21  Digital_life  阅读(3871)  评论(0编辑  收藏  举报

导航