Search code examples
pythonvisual-studio-codeexit-code

Python Projects In VSCode Exit With "code=1" When I Try to Run Them as Code


Title.

The specific message is:

[Running] python -u "d:\VSCode Projects\python.py"

[Done] exited with code=1 in 0.286 seconds

Non-python(specifically c++) projects work fine. Running and debugging the python file itself work normally. To be honest, I have no idea what the difference between running the code and running the file is. Would like to know the difference and why running the code doesn't work, as well as how to fix it if possible.

Thanks


Solution

  • enter image description here

    1. Run Code

    This option is provided by the extension Code-Runner, which is not an official extension provided by Python. Of course, this extension itself has many interesting functions.

    1. Run Python File

    This option is provided by Python extension. It is an officially supported option to run Python files. Usually, we will use this option.

    If you want to use the first one, you can add the following code to your settings.json:

    "code-runner.runInTerminal": true,
    

    If you don't want to use the first one, just delete the code runner extension in the extension store.

    enter image description here