Python

IndentationError: unexpected indent / unindent does not match

Python 3

IndentationError: unexpected indent — or 'unindent does not match any outer indentation level'.

What it means (root cause)

Python uses indentation for block structure; mixing tabs and spaces, or an inconsistent indent width, makes the parser unable to determine block nesting.

The symptom developers actually see: IndentationError: unexpected indent — or 'unindent does not match any outer indentation level'.

How to avoid it: Set the editor to 'spaces only' and a 4-space width; avoid copying snippets that mix tabs and spaces.

Step-by-step fix

Concrete, ordered steps from the dataset. Apply them in order; each line is a verified action, not generic advice.

  1. 1Configure the editor to insert spaces (4) on Tab and to show whitespace so tabs are visible.
  2. 2Re-indent the block consistently to one level (4 spaces) per nesting.
  3. 3Run python -m tabnanny <file> to locate the offending line automatically.

Where this error appears

Languages, frameworks, and runtimes where this error is observed (from the 2026 DevFixPro error dataset, retrieved 2026-08-29):

Python 3

Python 3 (PEP 8 mandates 4 spaces). tabnanny detects mixed tabs/spaces before runtime.

How to prevent it & common questions

Practical prevention plus the questions developers ask most about this error.

What does "IndentationError: unexpected indent / unindent does not match" mean?

Python uses indentation for block structure; mixing tabs and spaces, or an inconsistent indent width, makes the parser unable to determine block nesting.

Which environments are affected by IndentationError: unexpected indent / unindent does not match?

Python 3

How do I fix IndentationError: unexpected indent / unindent does not match?

Configure the editor to insert spaces (4) on Tab and to show whitespace so tabs are visible. Re-indent the block consistently to one level (4 spaces) per nesting. Run python -m tabnanny <file> to locate the offending line automatically.

How do I prevent IndentationError: unexpected indent / unindent does not match?

Set the editor to 'spaces only' and a 4-space width; avoid copying snippets that mix tabs and spaces.

Tabs or spaces in Python?

Spaces — four per level. Mixing tabs and spaces is the classic cause of IndentationError; configure the editor to insert spaces on Tab.

How do I find the bad line fast?

Run python -m tabnanny yourfile.py; it reports the exact file and line with the mixed-indentation problem.

Related DevFixPro tools

Real, browser-only utilities on DevFixPro that help while you work through this issue. These are navigation aids, not a substitute for the fix above.

● Data updated 2026-08-29

Sources & attribution

  • Error records aggregated from Google Search Console query gaps (2026-05-21~2026-08-18) for devfixpro.com, plus official framework docs (MDN, Node.js docs, Python docs, Go.dev, Rust book, Oracle Java docs, Docker docs, npm docs). Source dataset retrieved 2026-08-29. License: CC BY 4.0 — attribute DevFixPro (devfixpro.com).
  • Official reference: https://docs.python.org/3/reference/lexical_analysis.html#indentation
  • All cause, environment, fix and prevention text on this page is taken verbatim from the DevFixPro 2026 error dataset. DevFixPro does not invent root causes or fixes.
How this IndentationError: unexpected indent / unindent does not match page is built

Each error page is generated from a single record in the DevFixPro 2026 error dataset. The meaning, root cause, environments, fix steps, prevention, and official references are copied verbatim from that dataset and its official-doc sources; related-error links are computed from the error's category and explicit peer list. No root cause or fix is invented. The retrieval date for this dataset is 2026-08-29.

← Back to all errors