# SyntaxError: invalid syntax

**Code:** `SyntaxError` · **Category:** Python · **Seen on:** Python

Python couldn’t parse the code. The caret (^) points at or just after the mistake.

## Meaning

Missing colons, unclosed brackets on the previous line, using = instead of ==, Python 2 print statements and keywords used as names are common causes. Newer Pythons give more precise messages (“expected ':'”).

## Common causes

- Missing : after if/for/def
- Unclosed ( [ { on the line above
- print "x" (Python 2 syntax)
- Running new syntax (match, walrus) on an old Python
- Pasting shell commands (pip install) into the Python REPL

## Quick fix

1. Look at the line above the caret
2. Check Python version (python --version)
3. Run pip from the terminal, not inside python

## Detailed fix by platform

### Python

1. python -m py_compile file.py checks syntax without running

## How to diagnose

1. **Caret** — Where does ^ point?
2. **Previous line** — Unclosed bracket?
3. **Version** — Syntax supported?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/python/syntaxerror-invalid-syntax)
