close

[Solved] Invalid Syntax error when running python from inside Visual Studio Code

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Invalid Syntax error when running python from inside Visual Studio Code in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Invalid Syntax error when running python from inside Visual Studio Code Error Occurs?.

Today I get the following error Invalid Syntax error when running python from inside Visual Studio Code in python.

How To Solve Invalid Syntax error when running python from inside Visual Studio Code Error ?

  1. How To Solve Invalid Syntax error when running python from inside Visual Studio Code Error ?

    To Solve Invalid Syntax error when running python from inside Visual Studio Code Error 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.

  2. Invalid Syntax error when running python from inside Visual Studio Code

    To Solve Invalid Syntax error when running python from inside Visual Studio Code Error 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.

Solution 1

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.

Solution 2

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read