ChatGLM-6B
ChatGLM-6B copied to clipboard
[BUG/Help] 运行cli_demo.py时报错UnicodeDecodeError: 'utf-8' codec can't decode byte
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
Expected Behavior
No response
Steps To Reproduce
python cli_demo.py
@MaiziXiao api.py
web_demo.py
方式可以用吗?也不可以,你下载错误有问题,重新下载。
我也遇到了这个问题,似乎input("\n用户:")这句会引起这个错误。请问有解决办法吗?
这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。
补充一个方法: import readline
参考:https://github.com/imClumsyPanda/langchain-ChatGLM/issues/79
目前的代码中直接 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.
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.
感谢点拨,经过一系列的搜索,应该安装 pyreadline3
:https://stackoverflow.com/a/51964654/5719783
somehow,我这儿没有内置,诡异。
pyreadline3
同样遇到 No module named 'readline',环境 python3.8.0 Window10。安装 pyreadline3 解决,感谢~
在liunx环境下在代码中添加import readline,问题仍然存在
这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。
补充一个方法: import readline
请问大佬,try,catch应该加在哪里,有示例吗?
这个是input函数的问题。在输入错误的时候使用了退格键(backspace)。一次退格只删除一个char,一般utf8的汉字是3个char。所以需要按3次才能删除输入错误的字。 好一点的办法是加一个try ... except捕获这个错误输入,然后重新输入。 补充一个方法: import readline 参考:chatchat-space/langchain-ChatGLM#79
请问大佬,try,catch应该加在哪里,有示例吗?
import readline更方便解决。安装 pyreadline3