pythonpython-3.xubuntuvisual-studio-code

How to run python3 code in VSCode? /bin/sh: 1: python: not found


I'm trying to run a python file in VSCode using python3.

I know I can fix by simply setting to run using integrated terminal like it says in the microsoft vscode tutorial on python. However, I would like the program to print in the output tab and not take up the terminal window.

enter image description here

The standard code runner config file launch.json, looks like this;

"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    }
]

I've tried to set my python path in VSCode in settings.json

...
"python.pythonPath": "python3",
"code-runner.executorMap": {
    "python3": "/usr/bin/python3"
}

I've also set an alias for python -> python3 (as my ubuntu 20.04 doesn't come with python2 anymore)

alias python="python3"

However, I keep getting the above error. Any Ideas?


Solution

  • Solution in 2023

    Step1 : Goto settings of Code Runner extension

    Step2 : Find the section

    Code-runner: Executor Map

    And click on

    Edit in settings.json

    Step3 : Now change the setting for python

    Before

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

    Change this to

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