当 code-runner 运行在输出窗口时报错: Python was not found

1.png
有两种解决办法,都是修改配置 :
settings.json1. 将
code-runner输出移至vscode 的内置终端输出:
"code-runner.runInTerminal": true,
配置保存后重新运行:

2.png
- 指定
python路径: 先定义python路径,在配置code-runner内引用python路径
"python.pythonPath": "D:\\Soft\\Anaconda\\python.exe",
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
配置保存后运行:

3.png
可以运行了,但产生了新问题:中文乱码。
输出窗口中文乱码
也有两种解决办法:
- 见上面一个问题的第一种解决办法: 将
code-runner输出移动到vscode内置终端输出 前提是中文在终端内显示正常。 - 设置变量
PYTHONIOENCODING=utf8,以下方法二选一:
2.1 添加系统的环境变量
2.2 运行时先设置变量"code-runner.executorMap": { "python": "set PYTHONIOENCODING=utf8 & $pythonPath -u $fullFileName", },我使用了第二种方法,保存后运行:
4.png
使用 code-runner 运行时会运行文件注释头的命令 /usr/bin/env python,而非配置的 python
当 pyhont文件配置有文件头时,会产生以下错误:

5.png

6.png
修改配置:settings.json
"code-runner.respectShebang": false
保存后运行:

7.png
切换 conda 环境:
- 右下角选择
8.png -
Ctrl + Shift + P选择Pyhont: Interpreter
9.png


