
vscode 打开powershell出现编码报错问题解决
在windows上使用vscode打开终端powershell时,第一次打开总是出现以下报错,虽然可以正常使用,但是还是比较碍事。
1 | # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<< |
看源码可以知道是在 print(activator.execute(), end=“”) 时,遇到了 gbk 不兼容的编码,查资料得知:
- python 的 print 默认使用gbk,可以通过环境变量 PYTHONIOENCODING 改变默认编码。
- gbk 不包含所有的 unicode 字符
所以解决思路有两个,一个是在报错处改源代码,在上面插入:
1 | import io |
或者改 PYTHONIOENCODING,使用以下命令,或者在设置里面改,重启vscode生效。
1 | setx PYTHONIOENCODING "utf-8" |
This piece of writing is an original article, utilizing theCC BY-NC-SA 4.0Agreement. For complete reproduction, please acknowledge the source as Courtesy ofBlog of Shane Hu