Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
MaiziXiao opened this issue Apr 10, 2023 · 10 comments
Closed
1 task done

Comments

@MaiziXiao
Copy link

MaiziXiao commented Apr 10, 2023

Is there an existing issue for this?

  • 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

@mingyue0094
Copy link

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

@yinhaofeng
Copy link

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

@cifangyiquan
Copy link
Contributor

cifangyiquan commented May 5, 2023

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


补充一个方法:
import readline

参考:chatchat-space/Langchain-Chatchat#79

@chenshaoju
Copy link

目前的代码中直接 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
Copy link
Contributor

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.

@chenshaoju
Copy link

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

image

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

@awake1t
Copy link

awake1t commented Jun 12, 2023

pyreadline3

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

@Swag-Wang
Copy link

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

@wangcong607
Copy link

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

补充一个方法: import readline

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

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

@cifangyiquan
Copy link
Contributor

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

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

import readline更方便解决。安装 pyreadline3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants