當(dāng) code-runner 運(yùn)行在輸出窗口時(shí)報(bào)錯(cuò): Python was not found

1.png
有兩種解決辦法,都是修改配置 :
settings.json1. 將
code-runner輸出移至vscode 的內(nèi)置終端輸出:
"code-runner.runInTerminal": true,
配置保存后重新運(yùn)行:

2.png
- 指定
python路徑: 先定義python路徑,在配置code-runner內(nèi)引用python路徑
"python.pythonPath": "D:\\Soft\\Anaconda\\python.exe",
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
配置保存后運(yùn)行:

3.png
可以運(yùn)行了,但產(chǎn)生了新問題:中文亂碼。
輸出窗口中文亂碼
也有兩種解決辦法:
- 見上面一個(gè)問題的第一種解決辦法: 將
code-runner輸出移動(dòng)到vscode內(nèi)置終端輸出 前提是中文在終端內(nèi)顯示正常。 - 設(shè)置變量
PYTHONIOENCODING=utf8,以下方法二選一:
2.1 添加系統(tǒng)的環(huán)境變量
2.2 運(yùn)行時(shí)先設(shè)置變量"code-runner.executorMap": { "python": "set PYTHONIOENCODING=utf8 & $pythonPath -u $fullFileName", },我使用了第二種方法,保存后運(yùn)行:
4.png
使用 code-runner 運(yùn)行時(shí)會(huì)運(yùn)行文件注釋頭的命令 /usr/bin/env python,而非配置的 python
當(dāng) pyhont文件配置有文件頭時(shí),會(huì)產(chǎn)生以下錯(cuò)誤:

5.png

6.png
修改配置:settings.json
"code-runner.respectShebang": false
保存后運(yùn)行:

7.png
切換 conda 環(huán)境:
- 右下角選擇
8.png -
Ctrl + Shift + P選擇Pyhont: Interpreter
9.png


