Invalid Syntax error when running python from inside Visual Studio Code

Think this is a bug of VS Code.

When you use "run selection/line in python terminal" command, VS Code starts python interpreter and doesn`t quit it after completion.

You should use exit() command in python interpreter window to end python session.

After that "run python file in terminal" will work fine.


Looks like this is a bug in VS Code.

When i create a new file, assign python language to it and then save it then it works when i run the python file from within the editor.

But when i create a new file, assign python langauge but dont save it, execute "Run Selection/Line in Python Terminal" afterwards save it and then run "Run Python file in Terminal" it doen't work. So this seems to be an VS Code related issue.


The problem for me was that I accidentally used Shift + Return which executed the python program, when in fact I meant to hit CTRL + Return to move to the next line without touching the mouse.

Using exit() command in the console worked.


It's a probable bug in VS code. I don't know why there hasn't been a patch for this. After typing exit() in the terminal, the rerun should work fine. You could also try Ctrl+F5 to run in a debug mode.