ImportError: cannot import name 'Markup' from 'flask'
Fixes ImportError: cannot import name 'Markup' from 'flask' Use when Flask 3.x and anything doing `from flask import Markup` Not for: Flask < 3 (it warns but works)
How to fix ImportError: cannot import name 'Markup' from 'flask'
Flask 3 removed the flask.Markup re-export. Change from flask import Markup to from markupsafe import Markup. If it is a third-party extension (Flask-GoogleMaps, etc.), upgrade the extension; patching your own import takes ten seconds.
The exact error
ImportError: cannot import name 'Markup' from 'flask'Fix it
grep -rn "from flask import" --include=*.py . | grep Markupto find all occurrences.
Expected: list of files
- Replace with
from markupsafe import Markup.
Expected: app imports cleanly, tests pass
- Extension-owned?
pip install -U [extension].
Expected: upstream fix
When this applies
Flask 3.x and anything doing from flask import Markup
When this does NOT apply
Flask < 3 (it warns but works)
Versions
Flask >= 3.0 (deprecated since 2.0)
Why it happens
Flask deprecated re-exporting markupsafe names in 2.0, removed in 3.0.
Edge cases
markupsafe.Markup is the same class; behavior is identical.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.