pipenv: UnicodeDecodeError when running pipenv install on Windows
Issue 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'))}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 29 (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
Similar to #2820, but on Windows. Thanks for the debugging effort! I think I know what is going on here. Will fix in the next release.
Is there any solution for this? Still getting the error after setting the environment variable:
PYTHONLEGACYWINDOWSFSENCODING=mbcs
on version 2021.5.29@JalinWang Which accurate version is
the latest version
? I am still facing this issue in 2020.8.13For Windows10 users, possible solution is change system-wide default encoding to utf-8
Hint: this may break some old application which is incompatible with utf-8.
@JalinWang Thanks for the reminder!