Based on a quick glance through the tutorial, it looks like it might be a package version compatibility issue.

Have you tried upgrading Flask and Werkzeug to the latest versions?

Maybe try:

pip install Flask Werkzeug -U
Answer from Bradley on Stack Overflow
🌐
Werkzeug
werkzeug.palletsprojects.com › en › stable › local
Context Locals — Werkzeug Documentation (3.1.x)
If it’s not set, a RuntimeError is raised for most operations. from contextvars import ContextVar from werkzeug.local import LocalProxy _request_var = ContextVar("request") request = LocalProxy(_request_var) from werkzeug.wrappers import Request @Request.application def app(r): ...
🌐
GitHub
github.com › pallets › werkzeug › issues › 2163
cannot import name 'ContextVar' from 'werkzeug.local' · Issue #2163 · pallets/werkzeug
June 14, 2021 - $ python app.py Traceback (most recent call last): File "/vagrant/APIs/alpha/app.py", line 1, in <module> from flask import Flask, jsonify, request File "/usr/lib/python3.9/site-packages/flask/__init__.py", line 7, in <module> from .app import Flask as Flask File "/usr/lib/python3.9/site-packages/flask/app.py", line 19, in <module> from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/vagrant/.local/lib/python3.9/site-packages/werkzeug/local.py) Environment: Python version: Python 3.9.5 ·
Author   pallets
Discussions

python - ImportError cannot import name 'ContextVar' when using Werkzeug with FlaskAPI - Stack Overflow
Traceback (most recent call last): ... Flask File "/home/jnordling/.local/lib/python3.6/site-packages/flask/app.py", line 19, in from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar'... More on stackoverflow.com
🌐 stackoverflow.com
ImportError: cannot import name 'ContextVar' from 'werkzeug.local'
Flask is trying to import ContextVar which doesn't exist. Here is the minimum reproducible example: #!/usr/bin/env python3 import flask The output when I run this: root@fs1:/usr/src# ./test.py ... More on github.com
🌐 github.com
2
January 22, 2022
Issues with M1

Post the error

More on reddit.com
🌐 r/flask
8
1
January 8, 2022
python - How to secure a server-side session in flask? - Stack Overflow
cannot import name 'ContextVar' from 'werkzeug.local' More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › pallets › werkzeug › issues › 2324
cannot import name 'ContextVar' from 'werkzeug.local' · Issue #2324 · pallets/werkzeug
January 29, 2022 - File "/var/folders/03/20fw2gm138lgd8xy1khdjbt80000gn/T/zeit-fun-f7652521ec5a2/_lib/utils/auth.py", line 7, in <module> from flask import _request_ctx_stack, request File "/var/folders/03/20fw2gm138lgd8xy1khdjbt80000gn/T/zeit-fun-f7652521ec5a2/flask/__init__.py", line 7, in <module> from .app import Flask as Flask File "/var/folders/03/20fw2gm138lgd8xy1khdjbt80000gn/T/zeit-fun-f7652521ec5a2/flask/app.py", line 19, in <module> from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/var/folders/03/20fw2gm138lgd8xy1khdjbt80000gn/T/zeit-fun-f7652521ec5a2/werkzeug/local.py)
Author   pallets
🌐
Werkzeug
werkzeug.palletsprojects.com › en › latest › local
Context Locals — Werkzeug Documentation (3.2.x)
If it’s not set, a RuntimeError is raised for most operations. from contextvars import ContextVar from werkzeug.local import LocalProxy _request_var = ContextVar("request") request = LocalProxy(_request_var) from werkzeug.wrappers import Request @Request.application def app(r): ...
🌐
GitHub
github.com › pallets › flask › issues › 4429
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' · Issue #4429 · pallets/flask
January 22, 2022 - Flask is trying to import ContextVar which doesn't exist. ... root@fs1:/usr/src# ./test.py Traceback (most recent call last): File "./test.py", line 2, in <module> import flask File "/usr/local/lib/python3.7/dist-packages/flask/__init__.py", line 7, in <module> from .app import Flask as Flask File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 19, in <module> from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/usr/local/lib/python3.7/dist-packages/werkzeug/local.py)
Author   pallets
Find elsewhere
🌐
GitHub
github.com › pallets › werkzeug › blob › main › docs › local.rst
werkzeug/docs/local.rst at main · pallets/werkzeug
If it's not set, a RuntimeError is raised for most operations. from contextvars import ContextVar from werkzeug.local import LocalProxy _request_var = ContextVar("request") request = LocalProxy(_request_var) from werkzeug.wrappers import Request ...
Author   pallets
🌐
Readthedocs
mode.readthedocs.io › en › 4.0 › _modules › mode › locals.html
mode.locals — Mode 4.0.1 documentation
"""Implements thread-local stack using :class:`ContextVar` (:pep:`567`). This is a reimplementation of the local stack as used by Flask, Werkzeug, Celery, and other libraries to keep a thread-local stack of objects. - Supports typing: .. sourcecode:: python request_stack: LocalStack[Request] ...
🌐
PyPI
pypi.org › project › contextvars
contextvars
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Stack Overflow
stackoverflow.com › questions › 71257581 › flask-and-flask-restplus-dependency-conflicts-using-werkzeug
python - Flask and flask-restplus dependency conflicts using Werkzeug - Stack Overflow
flask-restplus is not compatible with the newer version of Werkzeug, it is however compatible with 0.16.1 due to an issue with the the import of: import name 'ContextVar' from 'werkzeug.local
🌐
GitHub
github.com › pallets › werkzeug › blob › main › src › werkzeug › local.py
werkzeug/src/werkzeug/local.py at main · pallets/werkzeug
The comprehensive WSGI web application library. Contribute to pallets/werkzeug development by creating an account on GitHub.
Author   pallets
🌐
Pocoo
mitsuhiko.pocoo.org › wzdoc › local.html
Context Locals — Werkzeug Documentation
It could be that a request is reusing a thread from before and data is left in the thread local object. ... from werkzeug import Local, LocalManager local = Local() local_manager = LocalManager([local]) def application(environ, start_response): local.request = request = Request(environ) ...
🌐
GitHub
github.com › pallets › flask › issues › 4015
2.0.0: build requires ContextVar module · Issue #4015 · pallets/flask
May 12, 2021 - Simple I cannot find it. + /usr/bin/python3 setup.py build '--executable=/usr/bin/python3 -s' Traceback (most recent call last): File "setup.py", line 4, in setup( File "/usr/lib/python3.8/site-packages/setuptools/__init__.py", ...
Author   pallets
🌐
Stack Overflow
stackoverflow.com › questions › 53255359 › local-file-from-flask-werkzeug-file-not-working
Local file from Flask Werkzeug file not working - Stack Overflow
""" werkzeug.local ~~~~~~~~~~~~~~ This module implements context-local objects. :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ import copy from functools import update_wrapper from werkzeug.wsgi import ClosingIterator from werkzeug._compat import PY2, implements_bool # since each thread has its own greenlet we can just use those as identifiers # for the context.
🌐
GitHub
github.com › pallets › werkzeug › pull › 1778
Switch locals to be based on ContextVars by pgjones · Pull Request #1778 · pallets/werkzeug
See also pallets/werkzeug#1778 for the future replacement of Quart's locals. pgjones force-pushed the local branch 2 times, most recently from 10b8d27 to 6bd6618 Compare ... I always mix up that the import is from Greenlet, not Gevent, it's shared by both Gevent and Eventlet. So if either library doesn't patch contextvars, the fallback keys off of greenlet.getcurrent().
Author   pallets