vscode中jupyter notebook执行bash命令,乱码解决方法

问题描述

使用vscode中使用jupyter notebook执行bash命令时,不管是中文还是英文,输出均是乱码
但是使用vscode的terminal执行同样的命令又没有问题,系统自带的cmd也没有问题。

最终解决后的效果如下:
## 问题分析

默认vscode会选择使用cmd执行shell, 但是通过vscode的设置修改好像只能影响到vscode的termial. 另外vscode设置项中的编码已经是utf-8了。

因此简单看修改配置好像不起作用。

在jupyter notebook中直接执行 !chcp可以看到默认的cmd code page, 发现是936. 参考:https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/chcp

这篇博文给出了解决方案,每次在vscode 的jupyter notebook执行shell命令前,先执行 !chcp 65001, 但是每次都要执行,实在太麻烦。

解决方法

修改计算机的注册表:

修改完成后,重启vscode, 然后在执行bash命令,发现乱码就没有了。唯一的缺陷是,不知道我的为什么第一次执行会乱码,然后再次运行shell命令就没有了。

参考:Change code page on windows

相关推荐
dingdingfish18 小时前
Bash学习 - 第10章:Installing Bash
bash·make·shell·install·configure·5.3
Tisfy20 小时前
Windows - VsCode导致Windows凭据过多之一键删除
ide·windows·vscode
dingdingfish1 天前
Bash学习 - 第8章:Command Line Editing,第3节:Readline Init File
bash·init·bind·readline
xzjiang_3652 天前
Jupyter 运行经验3:读入和显示一张图片
ide·python·jupyter
姜太小白2 天前
【VSCode/Trae】trae已安装的扩展如何导出
ide·vscode·编辑器
danyang_Q2 天前
vscode python-u问题
开发语言·vscode·python
dingdingfish2 天前
Bash学习 - 第8章:Command Line Editing,第6-8节:Programmable Completion
bash·shell·completion·complete·compgen·compopt
ChenYY~2 天前
手把手教你使用vscode开发stm32!
vscode·stm32·嵌入式·软件开发·学习经验
dingdingfish3 天前
Bash学习 - 第8章:Command Line Editing,第4-5节:Bindable Readline Commands
bash·emacs·vi·bind·readline
香芋Yu3 天前
【从零构建AI Code终端系统】02 -- Bash 工具:一切能力的基础
开发语言·bash·agent·claude