首页 > 解决方案 > VS Code 代码运行器扩展:由于空格而努力将 Python PATH 添加到 settings.json

问题描述

我正在尝试让 Code Runner 在我的 Windows 计算机上处​​理 VS 代码(尽管我使用 WSL 的大部分工作都涉及 Python)。我已经使用 Anaconda 安装了 Python

C:\\Users\\FirstName LastName\\anaconda3\\python.exe

您可能会注意到文件路径中的空格。

我已将其添加到我的settings.json...

{
    "terminal.integrated.inheritEnv": false,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "code-runner.executorMap": {
        "python": "C:\\Users\\FirstName LastName\\anaconda3\\python.exe",
    },
    "python.autoComplete.extraPaths": [


    ]
}

...但是当我使用 Code Runner 运行 Python 脚本时,我不断收到此错误:

[Running] C:\Users\FirstName LastName\anaconda3\python.exe "c:\Users\FirstName LastName\Documents\PythonFolder\pythonscript.py"
'C:\Users\FirstName' is not recognized as an internal or external command,
operable program or batch file.

看起来它对那里的空白不满意。我检查了另一个问题中提出的解决方案,该解决方案要添加"python": "python"settings.json,但这只是给了我这个:

'python' is not recognized as an internal or external command,
operable program or batch file.

知道如何进行这项工作吗?

标签: pythonvisual-studio-codecoderunner

解决方案


编辑您的代码运行器 setting.json 并添加此设置:

1.来自这个Qiita帖子

{
    "code-runner.executorMap": {
        "python": "python -u",
    },
}

或者 2.来自这个 StackOverFlow 帖子

{
    "code-runner.executorMap": {
        "python":"$pythonPath $fullFileName",
    },
}

或者 3.来自这个 NewBeDev 帖子

 {
    "code-runner.executorMap": {
        "python": "$pythonPath -u $fullFileName",
    },
}

只需尝试其中之一!


推荐阅读