V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
iktor
V2EX  ›  Python

请教大佬:安装 github 第三方库的时候出现 UnicodeDecodeError: 'gbk' codec can't decode..........如何解决?

  •  
  •   iktor · 99 天前 · 804 次点击
    这是一个创建于 99 天前的主题,其中的信息可能已经有所发展或是发生改变。

    安装 mesh2hrtf 时出现的,安装包链接如下: https://github.com/Any2HRTF/Mesh2HRTF/wiki/Installation_2#mesh2hrtf-python-package-installation

    报错信息如下: PS C:\Mesh2HRTF\Mesh2HRTF1.1.1> pip install -e . Defaulting to user installation because normal site-packages is not writeable Obtaining file:///C:/Mesh2HRTF/Mesh2HRTF1.1.1 Installing build dependencies ... done Checking if build backend supports build_editable ... done Getting requirements to build editable ... error error: subprocess-exited-with-error

    × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> [23 lines of output] Traceback (most recent call last): File "C:\Users\78347\AppData\Roaming\Python\Python311\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 353, in <module> main() File "C:\Users\78347\AppData\Roaming\Python\Python311\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\78347\AppData\Roaming\Python\Python311\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 132, in get_requires_for_build_editable return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\78347\AppData\Local\Temp\pip-build-env-b58n0u1h\overlay\Lib\site-packages\setuptools\build_meta.py", line 441, in get_requires_for_build_editable return self.get_requires_for_build_wheel(config_settings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\78347\AppData\Local\Temp\pip-build-env-b58n0u1h\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\78347\AppData\Local\Temp\pip-build-env-b58n0u1h\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires self.run_setup() File "C:\Users\78347\AppData\Local\Temp\pip-build-env-b58n0u1h\overlay\Lib\site-packages\setuptools\build_meta.py", line 480, in run_setup super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script) File "C:\Users\78347\AppData\Local\Temp\pip-build-env-b58n0u1h\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup exec(code, locals()) File "<string>", line 9, in <module> UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 3274: illegal multibyte sequence [end of output]

    note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

    × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> See above for output.

    6 条回复    2024-01-25 14:45:15 +08:00
    julyclyde
        1
    julyclyde  
       99 天前
    你把那个包单独下载下来看看 setup.py 里咋写的
    NoOneNoBody
        2
    NoOneNoBody  
       98 天前
    正确方法是去官方搜 issue ,或者提问

    自己排查的话,就是编码不合,需要确保读取的文件、输出的文件、console 是同一种编码
    windows console 默认跟随系统编码,文件如果没有声明也是默认系统编码
    gbk 表示你是中文 windows ,或者安装了中文语言包,且把中文( cp936 )作为默认编码

    note: This error originates from a subprocess, and is likely not a problem with pip.
    这句话应该是说运行(安装)过程调用了一个子进程,子进程的输出返回给主进程时产生错误,盲猜是 console 编码问题
    可以在安装前,console 运行
    chcp 65001
    这行命令
    如果不行可以试试 iso-8859-1 ,但还是建议询问官方

    PS:
    一般替代方案,备注,替代并非绝对全等的,只是说大部分可行,细微差别请查阅资料
    iso-8859-1 -> windows:windows-1252, python:latin-1 #纯英文
    gbk: windows: cp936, python:gbk #简体中文
    uft-8: windows: cp65001, python: utf8
    另外 utf 在 windows 默认是指 utf-16 ,ansi 默认是 8859-1 ,这是以前的事,但 windows 11 后增加了可以修改系统默认 utf-8 的功能,utf 的默认指向可能已经改变,请以最新文档为准。补充警告:虽然有这个功能,但目前兼容性较差,如非纯英语系统建议不要启用这个功能,很多软件界面会出错,甚至不能运行,会否导致蓝屏我就不清楚了
    littlewing
        3
    littlewing  
       98 天前 via iPhone
    不想折腾就换 Linux 或 WSL2 试试看
    makerbi
        4
    makerbi  
       98 天前
    如果是 Windows 下长期做开发的话,可以考虑打开全局 utf-8 ,能避免大部分编码问题

    ![PixPin_2024-01-20_14-37-56.jpg]( https://sapic.makerb.pro/static/upload/andersonby/PixPin_2024-01-20_14-37-56.jpg)
    makerbi
        5
    makerbi  
       98 天前
    如果是 Windows 下长期做开发的话,可以考虑打开全局 utf-8 ,能避免大部分编码问题
    iktor
        6
    iktor  
    OP
       93 天前
    太感谢各位大佬了,我先按照你们的方法试一下,如果还有什么问题再请教。谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2899 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:57 · PVG 16:57 · LAX 01:57 · JFK 04:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.