OpenAvatarChat要解决UnicodeDecodeError

 错误信息如下

ailed to import handler module client/h5_rendering_client/client_handler_lam
Traceback (most recent call last):
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\demo.py", line 82, in <module>
    main()
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\demo.py", line 75, in main
    chat_engine.initialize(engine_config, app=demo_app, ui=ui, parent_block=parent_block)
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\chat_engine\chat_engine.py", line 34, in initialize
    self.handler_manager.initialize(engine_config)
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\chat_engine\core\handler_manager.py", line 72, in initialize
    module = importlib.import_module(module_input_path)
  File "D:\ProgramSoftware\DevelopmentSoft\Anaconda3\envs\OpenAvatarChat\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\handlers\client\h5_rendering_client\client_handler_lam.py", line 26, in <module>
    from handlers.client.rtc_client.client_handler_rtc import RtcClientSessionDelegate, ClientHandlerRtc, \
  File "E:\Codes\Python\aigc\OpenAvatarChat\src\handlers\client\rtc_client\client_handler_rtc.py", line 9, in <module>
    from fastrtc import WebRTC
  File "E:\Codes\Python\aigc\OpenAvatarChat\.venv\lib\site-packages\fastrtc\__init__.py", line 15, in <module>
    from .stream import Stream, UIArgs
  File "E:\Codes\Python\aigc\OpenAvatarChat\.venv\lib\site-packages\fastrtc\stream.py", line 22, in <module>
    from .webrtc import WebRTC
  File "E:\Codes\Python\aigc\OpenAvatarChat\.venv\lib\site-packages\fastrtc\webrtc.py", line 51, in <module>
    class WebRTC(Component, WebRTCConnectionMixin):
  File "E:\Codes\Python\aigc\OpenAvatarChat\.venv\lib\site-packages\gradio\component_meta.py", line 218, in __new__
    create_or_modify_pyi(component_class, name, events)
  File "E:\Codes\Python\aigc\OpenAvatarChat\.venv\lib\site-packages\gradio\component_meta.py", line 133, in create_or_modify_pyi
    current_interface, _ = extract_class_source_code(pyi_file.read_text(), class_name)
  File "D:\ProgramSoftware\DevelopmentSoft\Anaconda3\envs\OpenAvatarChat\lib\pathlib.py", line 1135, in read_text
    return f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x88 in position 2963: illegal multibyte sequence

 

解决办法

 

要解决UnicodeDecodeError,可以按照以下步骤操作:

  1. 指定文件编码:修改gradio库中读取文件时的编码为UTF-8。

    • 找到component_meta.py文件,路径通常位于Lib\site-packages\gradio\component_meta.py

    • 在文件中找到pyi_file.read_text(),将其更改为pyi_file.read_text(encoding='utf-8')

  2. 设置环境变量(可选):在运行脚本前设置PYTHONUTF8=1,强制使用UTF-8编码。

    bash

  1. set PYTHONUTF8=1 && python your_script.py
  2. 更新库版本:检查gradiofastrtc是否有新版本,可能已修复此问题。

示例修改步骤

  1. 打开文件:.venv\Lib\site-packages\gradio\component_meta.py

  2. 搜索pyi_file.read_text(),替换为:

    python

  1. current_interface, _ = extract_class_source_code(pyi_file.read_text(encoding='utf-8'), class_name)
  2. 保存更改并重新运行程序。

原因:Windows默认使用GBK编码读取文件,而文件实际为UTF-8编码,导致解码失败。指定正确编码即可解决。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天机️灵韵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值