當(dāng) code-runner
運(yùn)行在輸出窗口時報錯: Python was not found
有兩種解決辦法,都是修改配置 :
settings.json
1. 將
code-runner
輸出移至vscode
的內(nèi)置終端輸出:
"code-runner.runInTerminal": true,
配置保存后重新運(yùn)行:
- 指定
python
路徑: 先定義python
路徑缀蹄,在配置code-runner
內(nèi)引用python
路徑
"python.pythonPath": "D:\\Soft\\Anaconda\\python.exe",
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
配置保存后運(yùn)行:
可以運(yùn)行了本慕,但產(chǎn)生了新問題:中文亂碼排拷。
輸出窗口中文亂碼
也有兩種解決辦法:
- 見上面一個問題的第一種解決辦法: 將
code-runner
輸出移動到vscode
內(nèi)置終端輸出 前提是中文在終端內(nèi)顯示正常。 - 設(shè)置變量
PYTHONIOENCODING=utf8
,以下方法二選一:
2.1 添加系統(tǒng)的環(huán)境變量
2.2 運(yùn)行時先設(shè)置變量"code-runner.executorMap": { "python": "set PYTHONIOENCODING=utf8 & $pythonPath -u $fullFileName", },
我使用了第二種方法间狂,保存后運(yùn)行:
使用 code-runner
運(yùn)行時會運(yùn)行文件注釋頭的命令 /usr/bin/env python
攻泼,而非配置的 python
當(dāng) pyhont
文件配置有文件頭時,會產(chǎn)生以下錯誤:
修改配置:settings.json
"code-runner.respectShebang": false
保存后運(yùn)行:
切換 conda
環(huán)境:
- 右下角選擇
-
Ctrl + Shift + P
選擇Pyhont: Interpreter