-1

Whenever I try to run the VS code python terminal, I get the following error:

File "<stdin>", line 1
    & C:/Users/tawsi/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/tawsi/OneDrive/Desktop/Coding/Untitled-1.py
    ^
SyntaxError: invalid syntax

Here is a picture of the Error

How can I fix this?? Please help

Barmar
  • 741,623
  • 53
  • 500
  • 612
Tawsif
  • 15
  • 1
  • 5
  • 3
    You can't run a Python file from the REPL, it's for typing Python statements. – Barmar Oct 20 '20 at 00:14
  • Refer to [this post](https://stackoverflow.com/questions/1027714/how-to-execute-a-file-within-the-python-interpreter). There are multiple ways to run a python script. – marcofkokasih Oct 20 '20 at 00:30

2 Answers2

2

This is because your current VSCode terminal is in the "Python interactive window", please try to use "exit()" to exit this interactive window, and then use the run button to execute the python script.

enter image description here

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
1

If you just want to run the python file in the VS Code terminal you install the Code Runner extension, after which you can right click on the workspace and click the "Run Python File in Terminal" option.

Ponyboy
  • 76
  • 5