问题:python安装在Program Files文件夹下,Code runner插件默认配置无法处理文件名空格,导致报错。
解决:首先,在VS Code的Setting中搜索code runner找到Code-runner: Executor Map点击Edit in setting.json
然后,将"python":部分内容替换为
"code-runner.executorMap": {
"python": "pwsh -Command \"$env:PYTHONIOENCODING='utf8'; & '${pythonPath}' -u '${fullFileName}'\""},
说明:
pwsh -Command
: 使用 PowerShell 执行命令;-
$env:PYTHONIOENCODING='utf8'
:解决输出乱码问题,设置环境变量为utf-8; '${pythonPath}'
:单引号=>字符串。