简体   繁体   中英

VS Code Code runner extension: Struggling to add Python PATH to settings.json due to whitespace

I am trying to get Code Runner to work on VS code on my Windows computer (although I use WSL most of my work involving Python). I have installed Python using Anaconda

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

You might notice the whitespace in the file path.

And I have added it to my 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": [


    ]
}

... and yet I keep getting this error when I run a Python script using Code Runner:

[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.

Looks like it's not happy with the whitespace there. I checked out a solution proposed in another question, whichw as to add "python": "python" to settings.json , but that just gave me this:

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

Any idea how to make this work?

Edit your code-runner setting.json and add this setting:

1.From this Qiita post

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

Or

2.From this StackOverFlow post

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

Or

3.From this NewBeDev post

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

Just try one of them!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM