Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 coder runner 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?

like image 421
Kaigo Avatar asked May 05 '20 18:05

Kaigo


People also ask

How do I run python3 in VS Code?

Configure VS Code for Python3 To get to that file, in vscode (mac) cmd+shift+P – type ' task ' – select ' configure task runner ', and edit the file to point the “ command ” at “ python3 ”, and the (command line) args to point at ${file} . Save, Debug/Run .. works! …

How do I fix bin sh Python not found Mac?

If this command does not return anything, it is likely that python is not installed (or undefined in the var env 'path') on your Mac. If you have a path to an interpreter, change the interpreter path used by vscode. Go to the settings and edit the field : "python : interpreter path" with the right one. Good day.

How do I activate Python code in Visual Studio?

To do so, open the Command Palette (Ctrl+Shift+P) and enter Preferences: Open User Settings. Then set python.defaultInterpreterPath , which is in the Python extension section of User Settings, with the appropriate interpreter.


1 Answers

Nearly had it. This code

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

should be

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

(The difference is at the beginning of line 3)

like image 111
Kaigo Avatar answered Sep 22 '22 23:09

Kaigo