LoginSignup
2
4

More than 5 years have passed since last update.

pipenv installがUnicodeDecodeErrorを起こす

Posted at

ある日何の気はなくpipenv installを実行しようとしたら、以下のエラーが出て実行に失敗するようになってしまいました。

Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python37\Scripts\pipenv.exe\__main__.py", line 5, in <module>
  File "c:\python37\lib\site-packages\pipenv\__init__.py", line 47, in <module>
    from .cli import cli
  File "c:\python37\lib\site-packages\pipenv\cli\__init__.py", line 3, in <module>
    from .command import cli
  File "c:\python37\lib\site-packages\pipenv\cli\command.py", line 7, in <module>
    import crayons
  File "c:\python37\lib\site-packages\pipenv\patched\crayons.py", line 49, in <module>
    is_powershell = "powershell" in shellingham.detect_shell()[0]
  File "c:\python37\lib\site-packages\pipenv\vendor\shellingham\__init__.py", line 22, in detect_shell
    shell = get_shell(pid, max_depth=max_depth)
  File "c:\python37\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 100, in get_shell
    processes = dict(_iter_process())
  File "c:\python37\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 78, in _iter_process
    info = {'executable': str(pe.szExeFile.decode('utf-8'))}
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 0: invalid start byte

いままでは動いていたのにおかしいなー、何もしていないのに動かなくなったなーと思っていろいろ原因を探っていたのですが、見当たらず。どうしたものかと思っていたら…。

答えは上記Tracebackの中にある
{python}\lib\site-packages\pipenv\vendor\shellingham\nt.pyに答えがありました。

上記プログラムの中には、Windows上で現在起動している全てのアプリを取得する という処理があります(逆にこれで全てのアプリ一覧が取れるんだ というのにも今気づいた)

lib\site-packages\pipenv\vendor\shellingham\nt.py
    success = windll.kernel32.Process32First(h_process, byref(pe))
    while True:
        if not success:
            errcode = windll.kernel32.GetLastError()
            if errcode == ERROR_NO_MORE_FILES:
                # No more processes to iterate through, we're done here.
                return
            elif errcode == ERROR_INSUFFICIENT_BUFFER:
                # This is likely because the file path is longer than the
                # Windows limit. Just ignore it, it's likely not what we're
                # looking for. We can fix this when it actually matters. (#8)
                continue
            raise WinError()
        info = {'executable': str(pe.szExeFile.decode('utf-8'))}
        if pe.th32ParentProcessID:
            info['parent_pid'] = pe.th32ParentProcessID
        yield pe.th32ProcessID, info
        success = windll.kernel32.Process32Next(h_process, byref(pe))

str(pe.szExeFile.decode('utf-8'))が「実行ファイル名が日本語」のアプリを検出すると上記の例外を発生させる ということのようです。

このため、該当のアプリをタスクマネージャより探して終了させればOK(今回の場合、「ラベル屋さん9.exe」でした)。

結論

Traceback見るの大事。

2
4
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
2
4