I'm reading "Let python do the boring things". Among them, there is a sample program that uses pyperclip, but when I use Japanese, it did not work with an error. The error was something like the following. (I'm sorry, I don't remember the last one) 「UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: ~~~~」
--Using python2.7 --Run python in VS Code
It was the above two points. Looking at issues on the original site, does Chinese support? It was reported that it did not work in Chinese. However, it was also reported that "If you specify utf-8 encoding, it will work ~", and it worked in my environment as well. However, another person reported that "it works even if you do not specify the encoding". In my environment, it doesn't work unless I specify the encoding ... why! !!
import sys
print('defaultencoding:', sys.getdefaultencoding())
Investigate which encoding is specified in the above code! As a result, "ascii"! why! !! Put in python3 and let it run on python3! !! I ran it with VS Code's task runner, so when I looked at which command I was running ... the letters "python"! Not python3! !! Change to python3 and investigate the default encoding again! The letters "utf-8"! Run pyperclip! Fall with the same error! !! I thought it was bad to run it with VS Code, so run it in the terminal! I was able to do it safely! !!
So I identified the cause. I don't know why it can't be executed with VS Code. .. .. I've just started studying python, so please point out anything strange!
** 2017/06/29: Addendum ** VS Code is the cause of the error, but it seems that VS Code has converted to ascii. github When I looked at it, there were a lot of issues. The solution presented by the developer is to add the sentence "" runner ":" terminal "" to "task.json". The point is that if you run it in the terminal, you won't get an error, so you should run it in the terminal. In my environment, the task no longer causes an error when running python. I wonder if it can't be fixed ...?
Recommended Posts