Python问题解决:OSError_ raw write() returned invalid length 14 (should have been between 0 and 7)

一次偶然的bug,我发现在VS code终端运行Python程序,Python中的print函数会出现上述OSError问题,然而我在外部cmd中运行该Python程序却不会出现该问题,所以在网上找了一下解决办法:可以使用pip install win_unicode_console安装win_unicode_console,在代码文件中添加以下两行代码解决:

1
2
import win_unicode_console
win_unicode_console.enable()

参考博客:在python中使用print()时,raw write()返回无效的长度:OSError: raw write() returned invalid length 254 (should have been between 0 and 127)

------本文结束感谢阅读------