Pipenv使用出現編碼錯誤UnicodeDecodeError: 'utf-8' codec can't decode ...
具體報錯如下
Traceback (most recent call last):
File "c:\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37-32\Scripts\pipenv.exe\__main__.py", line 5, in <module>
File "c:\python37-32\lib\site-packages\pipenv\__init__.py", line 23, in <module>
from .cli import cli
File "c:\python37-32\lib\site-packages\pipenv\cli\__init__.py", line 3, in <module>
from .command import cli
File "c:\python37-32\lib\site-packages\pipenv\cli\command.py", line 7, in <module>
import crayons
File "c:\python37-32\lib\site-packages\pipenv\patched\crayons.py", line 49, in <module>
is_powershell = "powershell" in shellingham.detect_shell()[0]
File "c:\python37-32\lib\site-packages\pipenv\vendor\shellingham\__init__.py", line 22, in detect_shell
shell = get_shell(pid, max_depth=max_depth)
File "c:\python37-32\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 100, in get_shell
processes = dict(_iter_process())
File "c:\python37-32\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 0xce in position 0: invalid continuation byte
原因:
mark 進程名有中文, 這行代碼 processes = dict(_iter_process())遍歷了進程列表
解決方法:
法一.既然解決不了問題,那就解決制造問題的進程把,找到那個中文進程名的殺死。
法二.重啟電腦就解決了。
還有的說法是:因為windows默認GBK編碼,所以報錯
最正確的解決方式不清楚,我的解決方式是修改源碼,親測有效:將你報錯位置的(報錯位置在你的錯誤信息里)str(pe.szExeFile.decode('utf-8') 改為 str(pe.szExeFile.decode('gbk')