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

相关推荐
egoist20231 天前
【Linux仓库】超越命令行用户:手写C语言Shell解释器,解密Bash背后的进程创建(附源码)
linux·c语言·bash·xshell·环境变量·命令行参数·内建命令
Lenyiin1 天前
《 Linux 修炼全景指南: 八 》别再碎片化学习!掌控 Linux 开发工具链:gcc、g++、GDB、Bash、Python 与工程化实践
linux·python·bash·gdb·gcc·g++·lenyiin
m0_743125131 天前
claude --version 报错Claude Code on Windows requires git-bash (https://git-scm.com/downloads/win).
开发语言·git·bash
风雨飘逸1 天前
【shell&bash进阶系列】(二十一)向脚本传递参数(shift和getopts)
linux·运维·服务器·经验分享·bash
24级计算机应用技术3班闫卓1 天前
Bash Shell 基础操作全面指南
开发语言·bash
悠悠子衿121381 天前
Claude+VSCODE配置git导致频繁弹出git bash 的CMO窗口解决方法
ide·git·vscode
wqfhenanxc1 天前
vscode/cursor 远程Linux基础命令
linux·ide·vscode
Balding Curry1 天前
vscode快速添加插件的3种方式
ide·vscode·编辑器
编程小Y2 天前
Bash 替换机制
开发语言·chrome·bash
嵌入式的猫2 天前
GD32或STM32使用vscode通过Cortex-Debug调试
vscode