0

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.

How can I make this work?

starball
  • 20,030
  • 7
  • 43
  • 238
Marielle Dado
  • 147
  • 1
  • 11
  • I think you have to escape the whitespace like this `C:\\Users\\FirstName\ Name\\anaconda3\\python.exe`. lmk if that works, or do as i did and install anaconda in a custom location (e.g. `C:\\anaconda\`) to avoid whitespace issues, btw, the anaconda installer also recommends installing python in a path without spaces because some python libraries don't handle that properly on windows. – Haleemur Ali Apr 30 '20 at 12:57
  • Have you added `python` to your system PATH? Does [this answer](https://stackoverflow.com/a/52458064/9374673) solve your problem? – Mihai Chelaru Apr 30 '20 at 12:58
  • @HaleemurAli I just tried it and it didn't work, it just removed the whitespace, `C:\\Users\\FirstNameLastName\\anaconda3\\python.exe` – Marielle Dado Apr 30 '20 at 14:03
  • @MihaiChelaru Unfortunately when I add `"code-runner.executorMap": {"python": "python",},"code-runner.respectShebang": false,` I just get the same error: `'python' is not recognized as an internal or external command, operable program or batch file.` – Marielle Dado Apr 30 '20 at 14:08
  • You need to [add Python to your system PATH](https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path). I suspect you'd get the same error if you went into `cmd.exe` and ran `python`. Doing this will help you in general, since you will likely come across this error again in the future if you ever want to run `python` from a terminal. – Mihai Chelaru Apr 30 '20 at 14:18
  • did installing to `c:\\anaconda3` help? – Haleemur Ali Apr 30 '20 at 14:28
  • So it turns out I wasn't running VS Code in WSL, which is what I wanted. Adding `"code-runner.executorMap": {"python": "python",},"code-runner.respectShebang": false` was enough to get it running, thank you! @HaleemurAli I think I might try to reinstall anaconda any to avoid the whitespace problem in the future – Marielle Dado Apr 30 '20 at 14:45

1 Answers1

1

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!

Vittore Marcas
  • 1,007
  • 8
  • 11