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
🌐
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
🌐
GitHub
github.com › pallets › werkzeug › issues › 2324
cannot import name 'ContextVar' from 'werkzeug.local' · Issue #2324 · pallets/werkzeug
January 28, 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
Discussions

Issues with M1

Post the error

More on reddit.com
🌐 r/flask
8
1
January 8, 2022
Flask SocketI) need to detect duplicate connections on opening new tab - Stack Overflow
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/werkzeug/local.py) More on stackoverflow.com
🌐 stackoverflow.com
python - How to secure a server-side session in flask? - Stack Overflow
The issue I am facing is that Werkzeug 1.0.0 has removed deprecated code, including all of Werkzeug.contrib so when I use flask-sessions I get from werkzeug.contrib.cache import FileSystemCache More on stackoverflow.com
🌐 stackoverflow.com
Downgrade doesn't fix 'werkzeug.contrib' Error
The issue I am facing is that Werkzeug 1.0.0 has removed deprecated code, including all of Werkzeug.contrib so when I use flask-sessions I get from werkzeug.contrib.cache import FileSystemCache Mod... More on github.com
🌐 github.com
1
June 20, 2021
🌐
Arch Linux
bugs.archlinux.org › task › 70815
FS#70815 : [python-flask] ImportError: cannot import name 'ContextVar' from 'werkzeug.local'
May 12, 2021 - Looks like it needs python-werkzeug 2.0.0+ Comment by Keith Hughitt (khughitt) - Thursday, 13 May 2021, 22:42 GMT
🌐
GitHub
github.com › pallets › flask › issues › 4429
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' · Issue #4429 · pallets/flask
ImportError: cannot import name 'ContextVar' from 'werkzeug.local'#4429 · Copy link · remdragon · opened · on Jan 22, 2022 · Issue body actions · Flask is trying to import ContextVar which doesn't exist. Here is the minimum reproducible example: #!/usr/bin/env python3 import flask ·
Author   pallets
🌐
Werkzeug
werkzeug.palletsprojects.com › en › stable › local
Context Locals — Werkzeug Documentation (3.1.x)
Werkzeug provides wrappers around ContextVar to make it easier to work with. LocalProxy allows treating a context var as an object directly instead of needing to use and check ContextVar.get(). If the context var is set, the local proxy will look and behave like the object the var is set to. 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): _request_var.set(r) check_auth() ...
🌐
GitHub
github.com › michaljach › python-flask-mongoengine-docker-starter › issues › 1
Issue with ContextVar from werkzeug.local · Issue #1 · michaljach/python-flask-mongoengine-docker-starter
example-web | Traceback (most recent call last): example-web | File "api/app.py", line 4, in example-web | from flask import Flask example-web | File "/usr/local/lib/python3.8/site-packages/flask/init.py", line 7, in example-web | from .app import Flask as Flask example-web | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 19, in example-web | from werkzeug.local import ContextVar example-web | ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/usr/local/lib/python3.8/site-packages/werkzeug/local.py)
Author   michaljach
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 68059378 › how-to-secure-a-server-side-session-in-flask
python - How to secure a server-side session in flask? - Stack Overflow
from werkzeug.contrib.cache import FileSystemCache ModuleNotFoundError: No module named 'werkzeug.contrib' So the solution suggested is to downgrade the werkzeug to 0.16.0 which I did. But now the issue is · cannot import name 'ContextVar' from 'werkzeug.local'
🌐
GitHub
github.com › pallets › werkzeug › issues › 2167
Downgrade doesn't fix 'werkzeug.contrib' Error · Issue #2167 · pallets/werkzeug
June 20, 2021 - from werkzeug.contrib.cache import ... name 'ContextVar' from 'werkzeug.local' For which the solution provided is to upgrade werkzeug to 2.0 or above....
Author   pallets
🌐
Werkzeug
werkzeug.palletsprojects.com › en › stable › changes
Changes — Werkzeug Documentation (3.1.x)
May 11, 2021 - Using gevent or eventlet requires greenlet>=1.0 or PyPy>=7.3.7. werkzeug.locals and contextvars will not work correctly with older versions. #2278 · Remove previously deprecated code. #2276 · Remove the non-standard shutdown function from the WSGI environ when running the development server.
🌐
GitHub
github.com › pallets › flask › issues › 4015
2.0.0: build requires ContextVar module · Issue #4015 · pallets/flask
May 11, 2021 - + /usr/bin/python3 setup.py build '--executable=/usr/bin/python3 -s' Traceback (most recent call last): File "setup.py", line 4, in <module> setup( File "/usr/lib/python3.8/site-packages/setuptools/__init__.py", line 144, in setup return distutils.core.setup(**attrs) File "/usr/lib64/python3.8/distutils/core.py", line 121, in setup dist.parse_config_files() File "/usr/lib/python3.8/site-packages/setuptools/dist.py", line 689, in parse_config_files parse_configuration(self, self.command_options, File "/usr/lib/python3.8/site-packages/setuptools/config.py", line 121, in parse_configuration meta.
Author   pallets
🌐
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
🌐
GitHub
github.com › lektor › lektor › issues › 909
Unable to install d/t Werkzeug / Flask / Lektor Dependency issue (temp fixed by rolling back flask.) · Issue #909 · lektor/lektor
May 24, 2021 - Installing collected packages: ... Werkzeug-2.0.1 Successfully installed Lektor-3.2.0 Werkzeug-0.16.1 · When I tried to run lektor quickstart or lektor server, I got this error: ImportError: cannot import name 'ContextVar' from 'werkzeug.local'...
Author   lektor
🌐
Werkzeug
werkzeug.palletsprojects.com › en › latest › local
Context Locals — Werkzeug Documentation (3.2.x)
Werkzeug provides wrappers around ContextVar to make it easier to work with. LocalProxy allows treating a context var as an object directly instead of needing to use and check ContextVar.get(). If the context var is set, the local proxy will look and behave like the object the var is set to. 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): _request_var.set(r) check_auth() ...
🌐
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
🌐
Fossies
fossies.org › linux › flask › src › flask › app.py
Fossies
Member "flask-2.2.0/src/flask/app.py" (2 Aug 2022, 97045 Bytes) of package /linux/www/flask-2.2.0.tar.gz: · As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line ...
🌐
Githubhot
githubhot.com › repo › pallets › flask › issues › 4429
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' - bytemeta
You need to use a recent Werkzeug version. If you install OS packages and get this combination you may want to report this as a bug to the maintainers of these packages. ... New project copied from an old one, instructions were to install that specific version of werkzeug because of ...