简体   繁体   English

Windows 上命令行启动时出现 Anaconda unicode 错误

[英]Anaconda unicode error on command line startup on Windows

I got this error when running python from command line on Windows 10:在 Windows 10 上从命令行运行 python 时出现此错误:

C:\Users\windows> python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site.py", line 410, in register_readline
    readline.read_history_file(history)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
    for line in open(filename, 'r'):
  File "C:\ProgramData\Anaconda3\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 991: character maps to <undefined>

I have not changed anything about my python environment, I was just running some scripts that I've been working on for the last week.我没有改变我的 python 环境,我只是在运行一些我上周一直在处理的脚本。 I honestly have no idea where this could be coming from;老实说,我不知道这可能来自哪里; it seems to be an issue when python reads in its history.当 python 读取其历史时,这似乎是一个问题。 Updating python and conda did nothing.更新 python 和 conda 什么也没做。 I found a very similar issue on a Chinese site here but the solution is unhelpful.我发现了一个非常类似的问题在中国的网站在这里,但解决的办法是无益的。

At the moment, I cannot find any issues when continuing to run python or my scripts, but I don't want this to come back and bite me.目前,我在继续运行 python 或我的脚本时找不到任何问题,但我不希望它回来咬我。 Any help is appreciated!任何帮助表示赞赏!

As user metatoaster commented , the python history file contains bytes that cannot be decoded by your system's default encoding and may be deleted.正如用户metatoaster 评论的那样,python 历史文件包含无法通过系统默认编码解码的字节,可能会被删除。 If the file contains commands that you want to keep or review you can take a backup first and try reviewing its contents in a text editor.如果文件包含您想要保留或查看的命令,您可以先备份并尝试在文本编辑器中查看其内容。

You have a history file that contain characters that cannot be decoded.您有一个历史文件,其中包含无法解码的字符。 Remove the history file (POSIX: ~/.python_history , on Windows it might be %userprofile%/.python_history ) and see if that problem goes away.删除历史文件(POSIX: ~/.python_history ,在 Windows 上它可能是%userprofile%/.python_history )并查看该问题是否消失。

在“history.py”文件中,尝试将“for line in open(filename, 'r'):”更改为“for line in open(filename, 'r', encoding='utf-8'):”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM