Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Code Runner always open other terminal in VSCode when I execute Python? And how to fix it?

Even though there is already a terminal open, when I run Python code using Code Runner (ctrl + alt + n), in VSCode it always opens another terminal. And it's no use closing the old one, because it opens again.

enter image description here

This is my configurations for terminal, Python and Code Runner:

Terminal:

"terminal.integrated.copyOnSelection": true,
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.letterSpacing": 1,

Code Runner:

"code-runner.clearPreviousOutput": true,
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.ignoreSelection": true,
"code-runner.runInTerminal": true, //only 2 Python
"code-runner.executorMap": {
    "javascript": "node",

    "python": "venv\\Scripts\\python.exe -u", //code-runner exec python of venv
    "bat": "cmd /c"
},

Python:

"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500,

"[python]": {
    "editor.defaultFormatter": "ms-python.python",
    "editor.insertSpaces": true
},

"python.pythonPath": "venv\\Scripts\\python.exe",
"python.analysis.completeFunctionParens": true,
"python.linting.flake8Enabled": true,
"python.linting.pycodestyleEnabled": true,
"python.linting.pycodestylePath": "[MyPathHere]",
"python.linting.flake8Path": "[MyPathHere]",
"python.formatting.provider": "black"

How I can fix this strange behavior?

Thx

like image 843
M.F Avatar asked Oct 19 '25 02:10

M.F


1 Answers

This is a problem with code runners clear previous output , set it to false and add clear command manually to its executor map, the final result should look like this. All this is to be done in the project's settings.json file, under .vscode folder.

{
    "code-runner.runInTerminal": true,
    "code-runner.clearPreviousOutput": false,
    "code-runner.executorMap": {
        "c": "clear; cd $dir && gcc $fileName -o $fileNameWithoutExt && 
                   $dir$fileNameWithoutExt",
        "cpp": "clear; cd $dir && g++ $fileName -o $fileNameWithoutExt && 
                   $dir$fileNameWithoutExt",
    }
}
like image 182
Mihir Patel Avatar answered Oct 20 '25 17:10

Mihir Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!