Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

python - Anaconda unicode error on command line startup on Windows

I got this error when running python from command line on Windows 10:

C:Userswindows> 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:ProgramDataAnaconda3libsite.py", line 410, in register_readline
    readline.read_history_file(history)
  File "C:ProgramDataAnaconda3libsite-packagespyreadline
lmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "C:ProgramDataAnaconda3libsite-packagespyreadlinelineeditorhistory.py", line 82, in read_history_file
    for line in open(filename, 'r'):
  File "C:ProgramDataAnaconda3libencodingscp1252.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. I honestly have no idea where this could be coming from; it seems to be an issue when python reads in its history. Updating python and conda did nothing. 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. Any help is appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As user metatoaster commented, the python history file contains bytes that cannot be decoded by your system's default encoding and may be deleted. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...