UnicodeDecodeError occurs in pip (Windows environment)

When I installed PyYAML using pip on Windows, I got a UnicodeDecodeError and could not install it, so this is the solution.

environment

Windows 7 Professional SP1 64bit Python 3.6.1 (64bit) pip 9.0.1

error contents

When I try to install PyYAML, I get a UnicodeDecodeError ...

python


>pip install PyYAML
Collecting PyYAML
  Using cached PyYAML-3.12.tar.gz
Installing collected packages: PyYAML
  Running setup.py install for PyYAML ... error
Exception:
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 80: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\python36\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "c:\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 80: invalid start byte

Solution

The problem was solved by changing the character code of the command prompt to "UTF-8".

1) Check the character code of the command prompt.

python


>chcp
Current code page: 932

If "932" is displayed by the chcp command, the character code is "Shift JIS".

2) Change the character code of the command prompt

You can change the character code to "UTF-8" by specifying "65001" with the chcp command.

python


>chcp 65001
Active code page: 65001

3) Install PyYAML

PyYAML was successfully installed.

python


>pip install PyYAML
Collecting PyYAML
  Using cached PyYAML-3.12.tar.gz
Installing collected packages: PyYAML
  Running setup.py install for PyYAML ... done
Successfully installed PyYAML-3.12

Postscript

I also got a UnicodeDecodeError when installing the mstranslator package. http://qiita.com/akabei/items/2356bb1ac282f6dd2a45

This was not solved by the method of this article, so I solved it by referring to the following article.

The point of introducing Python external modules on Windows http://qiita.com/yukinoi/items/1fe023408d3e684da983

When developing Python on Windows, there are some character code problems ...

Recommended Posts

UnicodeDecodeError occurs in pip (Windows environment)
virtualenvwrapper in windows environment
Pip install in proxy environment
What to do if a UnicodeDecodeError occurs in pip
Until you install TensorFlow-GPU with pip in Windows environment
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
Pip install (Windows) under Proxy environment
Install Jupiter Notebook on Windows with pip in proxy environment
Set up Pipenv in Pycharm in Windows environment
Python garbled in Windows + Git Bash environment
Let's install box2d-py with Windows 10 environment pip
[pip3] ImportError occurs
Run PIFuHD in Windows + Anaconda + Git Bash environment
Browser specification of Jupyter Notebook in Windows environment
Install Python 3.5.1 + numpy + scipy + α in Windows environment
python windows environment construction
Execute Language Interpretability Tool (LIT) in Windows 10 environment (1. Environment construction)
UnicodeDecodeError in pandas read_csv
virtual environment in python
How to use jupyter lab in Windows 10 local environment
Development environment in Python
Use pip on Windows
Force luigi to do parallel processing in windows environment
Seaborn, matplotlib garbled characters resolved in Windows10, Anaconda virtual environment
I tried the super-resolution algorithm "PULSE" in a Windows environment
How to use VS Code in venv environment on windows
A story that stumbled when using pip in a proxy environment
Double-click ipynb in windows + anaconda environment to open with jupyter-notebook
[Windows 10] [Development environment construction] How to resolve when unresolved import'django.xxx' python (unresolved-import) occurs in VS Code
Use Anaconda in pyenv environment
SSH restrictions in Linux environment
Collaborate in a remote environment
Prepare Chainer environment on Windows
Python environment construction (Windows10 + Emacs)
Resolve UnicodeDecodeError in kivy JsonStore
Build Python environment on Windows
Django environment development on Windows 10
Byobu crashes in pyenv environment
Build python environment on windows
Introducing Python in Practice (PiP)
Python environment construction under Windows7 environment
(Note) Django in Vagrant environment
[Tensorflow] Tensorflow environment construction on Windows 10
Create a Python environment for professionals in VS Code on Windows
Install pip in Serverless Framework and AWS Lambda with Python environment
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
Error in ordinal number when importing Numpy in Anaconda environment of Windows
Install deep learning environment offline on Windows (Tensorflow, Keras) ・ ・ ・ It may be called "pip installation method in offline environment" ...