Search code examples
pythonsyntax-error

I get a syntax error about File "<stdin>", line 1


This is the error, I have no idea where the fault is:

> & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe  
"c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"
  File "<stdin>", line 1
    & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"
    ^
SyntaxError: invalid syntax

Solution

  • You're getting a Python SyntaxError because you are trying to run a PowerShell command in the Python shell:

    >>> & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"
    

    exit() out of that shell and then run your PowerShell command in PowerShell. The prompt should look something like

    PS C:\>
    

    The Python shell is for running code interactively, e.g. you could type something like import pygame or print("Hello, world!") directly into it.