【已解决】Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte

在Windows10上使用Python3.7及以上版本时,通过pip安装weditor遇到UnicodeDecodeError,原因是系统默认编码为gbk而非utf-8。为避免频繁修改系统编码,可以在环境变量中设置PYTHONUTF8来指定编码为utf-8,参考PEP提案和Python官方文档可以找到解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: 'gbk' codec can't decode byte

#Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: ‘gbk’ codec can’t decode byte

在Win 10环境下,使用pip install -U weditor报错

    File "C:\Python310\lib\email\parser.py", line 53, in parse
      data = fp.read(8192)
  UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 825: illegal multibyte sequence

原因

编码问题,代码中默认使用gbk,但是需要改为utf-8
python 2 版本下可以通过调用代码修改默认编码,但是这种办法 python 3 中行不通。而且我也不想老是修改 win10 的系统编码,每次调整都要重启。

解决办法

在系统环境变量中增加:
在这里插入图片描述

参考资料

有关的使用说明和 pep 提案:

https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUTF8

https://www.python.org/dev/peps/pep-0540/

Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [30 lines of output] C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\util.py:75: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. import pkg_resources Error parsing Traceback (most recent call last): File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\core.py", line 105, in pbr attrs = util.cfg_to_args(path, dist.script_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\util.py", line 272, in cfg_to_args pbr.hooks.setup_hook(config) File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\hooks\__init__.py", line 25, in setup_hook metadata_config.run() File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\hooks\base.py", line 27, in run self.hook() File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\hooks\metadata.py", line 25, in hook self.config[&#39;version&#39;] = packaging.get_version( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\packaging.py", line 854, in get_version version = _get_version_from_pkg_metadata(package_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\26289\AppData\Local\Temp\pip-build-env-_uaj_44a\normal\Lib\site-packages\pbr\packaging.py", line 822, in _get_version_from_pkg_metadata pkg_metadata = email.message_from_file(pkg_metadata_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\toos\python\Lib\email\__init__.py", line 53, in message_from_file return Parser(*args, **kws).parse(fp) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\toos\python\Lib\email\parser.py", line 52, in parse while data := fp.read(8192): ^^^^^^^^^^^^^ UnicodeDecodeError: &#39;gbk&#39; codec can&#39;t decode byte 0xad in position 795: illegal multibyte sequence error in setup command: Error parsing C:\Users\26289\AppData\Local\Temp\pip-install-yrpn9_um\weditor\setup.cfg: UnicodeDecodeError: &#39;gbk&#39; codec can&#39;t decode byte 0xad in position 795: illegal multibyte sequence [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 25.0.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> weditor note: This is an issue with the package mentioned above, not pip. hint: See above for details.
最新发布
06-29
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值