Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.


pipenv installがUnicodeDecodeErrorを起こす

ある日何の気はなく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



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

    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.
            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)
            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'))が「実行ファイル名が日本語」のアプリを検出すると上記の例外を発生させる ということのようです。




Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What is going on with this article?