UnicodeDecodeError when running pipenv install on Windows
See original GitHub issueIssue description
I’m installing a pipenv virtual env from a virtualenv project that has a requirement.txt, but it doesn’t matter, I can’t run any pipenv commands, even pipenv --support.
Expected result
Installation should be successful.
Actual result
pipenv install or pipenv --support
Traceback (most recent call last): File “c:\users\panzi\appdata\local\programs\python\python36\lib\runpy.py”, line 193, in run_module_as_main “main”, mod_spec) File “c:\users\panzi\appdata\local\programs\python\python36\lib\runpy.py”, line 85, in run_code exec(code, run_globals) File "C:\Users\panzi\AppData\Local\Programs\Python\Python36\Scripts\pipenv.exe_main.py", line 5, in <module> File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv_init.py", line 47, in <module> from .cli import cli File “c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli_init_.py”, line 3, in <module> from .command import cli File “c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli\command.py”, line 7, in <module> import crayons File “c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\patched\crayons.py”, line 49, in <module> is_powershell = “powershell” in shellingham.detect_shell()[0] File “c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\shellingham_init_.py”, line 22, in detect_shell shell = get_shell(pid, max_depth=max_depth) File “c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\shellingham\nt.py”, line 100, in get_shell processes = dict(_iter_process()) File “c:\users\panzi\appdata\local\programs\python\python36\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 0xc3 in position 2: invalid continuation byte
Steps to replicate
pipenv install
After some debugging, I found it’s a decoding bug in Python36\Lib\site-packages\pipenv\vendor\shellingham\nt.py
I added a try catch to capture the exception and try to decode it in my locale encoding, then it succeeded. Is there a more elegant way to fix it?
def _iter_process():
...
try:
info = {'executable': str(pe.szExeFile.decode('utf-8'))}
except UnicodeDecodeError:
info = {'executable': str(pe.szExeFile.decode('GBK'))}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:28 (11 by maintainers)
When can we include this fix? There are no releases for almost a year since the last pipenv release. https://github.com/sarugaku/shellingham/commit/381372076a075dd3e5eea9d1cfe6644e48b60aa8
Same error when running
pipenv install
, on Windows 10 (Chinese). Caused by some network errors in Chinese. Fixed by adding an environment variable:PYTHONLEGACYWINDOWSFSENCODING=mbcs