ChatGLM-6B icon indicating copy to clipboard operation
ChatGLM-6B copied to clipboard

[BUG/Help] 运行cli_demo.py时报错UnicodeDecodeError: 'utf-8' codec can't decode byte

Open MaiziXiao opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

Traceback (most recent call last): File "cli_demo.py", line 57, in main() File "cli_demo.py", line 33, in main query = input("\n用户:") UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position 6: invalid continuation byte

Expected Behavior

No response

Steps To Reproduce

python cli_demo.py

MaiziXiao avatar Apr 10 '23 09:04 MaiziXiao

@MaiziXiao api.py web_demo.py 方式可以用吗?也不可以,你下载错误有问题,重新下载。

mingyue0094 avatar Apr 11 '23 12:04 mingyue0094

我也遇到了这个问题,似乎input("\n用户:")这句会引起这个错误。请问有解决办法吗?

yinhaofeng avatar Apr 26 '23 17:04 yinhaofeng

这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。


补充一个方法: import readline

参考:https://github.com/imClumsyPanda/langchain-ChatGLM/issues/79

cifangyiquan avatar May 05 '23 08:05 cifangyiquan

目前的代码中直接 import readline,但是这有一个问题,readline不支持Windows,导致彻底无法使用。

错误代码如下:

E:\AI\Python3.10\userfolder\ChatGLM-6B-main>python cli.py
Traceback (most recent call last):
  File "E:\AI\Python3.10\userfolder\ChatGLM-6B-main\cli.py", line 5, in <module>
    import readline
ModuleNotFoundError: No module named 'readline'

E:\AI\Python3.10\userfolder\ChatGLM-6B-main>python -m pip install readline
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting readline
  Downloading https://mirrors.aliyun.com/pypi/packages/f4/01/2cf081af8d880b44939a5f1b446551a7f8d59eae414277fd0c303757ff1b/readline-6.2.4.1.tar.gz (2.3 MB)
     ---------------------------------------- 2.3/2.3 MB 9.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      error: this module is not meant to work on Windows
      [end of output]

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

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

chenshaoju avatar May 19 '23 05:05 chenshaoju

readline是python3的内置模块,应该不需要安装。 我在windows下测试可用。 windows 10 powershell 7(x64) python 3.8 conda安装

目前的代码中直接 import readline,但是这有一个问题,readline不支持Windows,导致彻底无法使用。

错误代码如下:

E:\AI\Python3.10\userfolder\ChatGLM-6B-main>python cli.py
Traceback (most recent call last):
  File "E:\AI\Python3.10\userfolder\ChatGLM-6B-main\cli.py", line 5, in <module>
    import readline
ModuleNotFoundError: No module named 'readline'

E:\AI\Python3.10\userfolder\ChatGLM-6B-main>python -m pip install readline
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting readline
  Downloading https://mirrors.aliyun.com/pypi/packages/f4/01/2cf081af8d880b44939a5f1b446551a7f8d59eae414277fd0c303757ff1b/readline-6.2.4.1.tar.gz (2.3 MB)
     ---------------------------------------- 2.3/2.3 MB 9.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      error: this module is not meant to work on Windows
      [end of output]

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

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

cifangyiquan avatar May 22 '23 02:05 cifangyiquan

感谢点拨,经过一系列的搜索,应该安装 pyreadline3 :https://stackoverflow.com/a/51964654/5719783

image

somehow,我这儿没有内置,诡异。

chenshaoju avatar May 22 '23 03:05 chenshaoju

pyreadline3

同样遇到 No module named 'readline',环境 python3.8.0 Window10。安装 pyreadline3 解决,感谢~

awake1t avatar Jun 12 '23 15:06 awake1t

在liunx环境下在代码中添加import readline,问题仍然存在

Swag-Wang avatar Jul 12 '23 16:07 Swag-Wang

这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。

补充一个方法: import readline

参考:chatchat-space/langchain-ChatGLM#79

请问大佬,try,catch应该加在哪里,有示例吗?

wangcong607 avatar Aug 03 '23 03:08 wangcong607

这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。 补充一个方法: import readline 参考:chatchat-space/langchain-ChatGLM#79

请问大佬,try,catch应该加在哪里,有示例吗?

import readline更方便解决。安装 pyreadline3

cifangyiquan avatar Aug 03 '23 06:08 cifangyiquan