LoginSignup
64
60

More than 5 years have passed since last update.

pipでUnicodeDecodeErrorが発生(Windows環境)

Last updated at Posted at 2017-04-23

Windowsでpipを使ってPyYAMLをインストールしたらUnicodeDecodeErrorが発生してインストールできなかったのでその解決方法です。

環境

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

エラー内容

PyYAMLをインストールしようとするとUnicodeDecodeErrorが発生してしまう・・・。

>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

解決方法

コマンドプロンプトの文字コードを「UTF-8」にすることで解決しました。

1)コマンドプロンプトの文字コードを確認する。

>chcp
現在のコード ページ: 932

chcpコマンドで「932」と表示されたら文字コードは「ShiftJIS」になっています。

2)コマンドプロンプトの文字コードを変更する

chcpコマンドで「65001」を指定すると文字コードを「UTF-8」に変更できます。

>chcp 65001
Active code page: 65001

3)PyYAMLインストール

PyYAMLが正常にインストールできました。

>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

追記

mstranslatorパッケージのインストールでもUnicodeDecodeErrorが発生しました。
http://qiita.com/akabei/items/2356bb1ac282f6dd2a45

こちらは本記事の方法では解決しなかったので、以下の記事を参考に解決しました。

WindowsでのPython外部モジュール導入のはまりどころ
http://qiita.com/yukinoi/items/1fe023408d3e684da983

WindowsでPythonの開発をすると文字コードの問題がわりとありますね・・・。

64
60
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
64
60