Flask crashes on start with cannot import name url_quote from werkzeug.urls
Fix it fast
Most common cause, 1 of 3An old Flask release was installed next to Werkzeug 3
Move to a current Flask; 2.2.4 was the first release updated for Werkzeug 2.3, and Flask 3.1.3 needs Werkzeug 3.1 or later.
# preferred
python -m pip install --upgrade "flask==3.1.3" "werkzeug==3.1.9"
# stop-gap for an app stuck on Flask 2.2.3 or older
python -m pip install "werkzeug<3"Short answer
ImportError: cannot import name 'url_quote' from 'werkzeug.urls' means a Flask release older than 2.2.4 met Werkzeug 3, which removed most of werkzeug.urls. Old Flask allows any newer Werkzeug, so a fresh install breaks. Upgrade to Flask 3.1.3 with Werkzeug 3.1.9, or pin werkzeug<3 until you can. Extensions such as Flask-Login 0.6.2 fail the same way.
Which cause do you have?
Print the installed versions, then read the file path in the last frame of the traceback. Flask below 2.2.4 with Werkzeug 3.x points to cause 1. A path inside another package's folder points to cause 2, and a path in your own project to cause 3.
python -m pip show flask werkzeug flask-login | grep -E '^(Name|Version)'Then find the line you see in this list and open its fix:
- 1An old Flask release was installed next to Werkzeug 3
pip show prints Flask 2.2.3 or lower with Werkzeug 3.x, and the traceback ends in flask/app.py or flask/helpers.py - 2A Flask extension still calls the removed helpers
The last traceback frame sits in site-packages/flask_login or another extension, and the missing name may be url_decode or url_encode instead of url_quote - 3Your own code imports url_quote or its siblings
The traceback points to a file in your repository with a from werkzeug.urls import line
What does the error look like?
ImportError: cannot import name 'url_quote' from 'werkzeug.urls'from werkzeug.urls import url_quoteImportError: cannot import name 'url_decode' from 'werkzeug.urls'
Cause 1 of 3
An old Flask release was installed next to Werkzeug 3
You seepip show prints Flask 2.2.3 or lower with Werkzeug 3.x, and the traceback ends in flask/app.py or flask/helpers.py
Check
Flask 2.2.0 to 2.2.3 import url_quote from werkzeug.urls in flask/app.py, and Flask 2.0 and 2.1 do it in flask/helpers.py. Their install rules ask only for a minimum Werkzeug, so pip picks the newest one. Werkzeug 2.3 deprecated the werkzeug.urls helpers and 3.0 deleted them, so the import fails before your app runs.
grep -rn "werkzeug.urls" $(python -c 'import flask, os; print(os.path.dirname(flask.__file__))')Fix
Move to a current Flask; 2.2.4 was the first release updated for Werkzeug 2.3, and Flask 3.1.3 needs Werkzeug 3.1 or later. If the app cannot move yet, pin Werkzeug to the 2.x line in the same requirements file as a short-term patch.
# preferred
python -m pip install --upgrade "flask==3.1.3" "werkzeug==3.1.9"
# stop-gap for an app stuck on Flask 2.2.3 or older
python -m pip install "werkzeug<3"Verify
The app module imports and the server starts without the ImportError.
python -c "import flask, importlib.metadata as m; print(m.version('flask'), m.version('werkzeug'))"Confirmed by raw.githubusercontent.com
Cause 2 of 3
A Flask extension still calls the removed helpers
You seeThe last traceback frame sits in site-packages/flask_login or another extension, and the missing name may be url_decode or url_encode instead of url_quote
Check
Extensions built before Werkzeug 3 import the same helpers. Flask-Login 0.6.2 imports url_decode and url_encode from werkzeug.urls, so it breaks even on a new Flask. Its 0.6.3 release added compatibility with Flask 3 and Werkzeug 3.
python -m pip show flask-login | grep VersionFix
Upgrade the extension to a release that supports Werkzeug 3. For Flask-Login that is 0.6.3. If an extension has no such release, replace it, or keep Werkzeug below 3 until it is gone.
python -m pip install --upgrade "flask-login==0.6.3"Verify
Importing the extension works on Werkzeug 3.
python -c "import flask_login; print('ok')"Confirmed by raw.githubusercontent.com
Cause 3 of 3
Your own code imports url_quote or its siblings
You seeThe traceback points to a file in your repository with a from werkzeug.urls import line
Check
Werkzeug 2.3 marked the werkzeug.urls module as deprecated except uri_to_iri and iri_to_uri, and told users to switch to the standard urllib.parse library. Code that still imports url_quote, url_parse or url_encode stops working on 3.0.
grep -rn "from werkzeug.urls import" --include='*.py' .Fix
Use the standard library: quote for url_quote, urlsplit for url_parse, urlencode for url_encode and parse_qs for url_decode. The return types differ: urlsplit gives a SplitResult tuple and parse_qs a dict of lists, so check what your code reads from them.
# before
from werkzeug.urls import url_quote, url_encode
# after
from urllib.parse import quote, urlencode
safe_path = quote(file_name)
query = urlencode({"page": 2, "q": "red shoes"})Verify
grep finds no werkzeug.urls imports left except uri_to_iri or iri_to_uri, and the test suite passes.
grep -rn "werkzeug.urls" --include='*.py' .Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Write Flask and Werkzeug side by side with exact versions in requirements.txt, and change them in the same commit.
- Run the tests with python -W error::DeprecationWarning -m pytest, so a helper that is deprecated today fails in CI before the next major release removes it.
- Build the Docker image in CI on every dependency change and import the app module in it, so a new resolver result breaks the build, not production.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.