'Flask and flask-restplus dependency conflicts using Werkzeug

I am writing an API using Flask, flask-restplus, Werkzeug, and a few other irrelevant libraries. Here is the issue:

  1. 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

my traceback:

web  | Traceback (most recent call last):
web  |   File "./main.py", line 7, in <module>
web  |     from app import app
web  |   File "./app/__init__.py", line 7, in <module>
web  |     from flask import Flask, Blueprint, jsonify
web  |   File "/usr/local/lib/python3.6/site-packages/flask/__init__.py", line 7, in <module>
web  |     from .app import Flask as Flask
web  |   File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 19, in <module>
web  |     from werkzeug.local import ContextVar
web  | ImportError: cannot import name 'ContextVar'
web  | unable to load app 0 (mountpoint='') (callable not found or import error)

issue on github: https://github.com/noirbizarre/flask-restplus/issues/777

  1. Flask is not compatible with the older version of Werkzeug 0.16.1 due to an import error of ImportError: cannot import name 'cached_property'

my traceback:

web  | Traceback (most recent call last):
web  |   File "./main.py", line 7, in <module>
web  |     from app import app
web  |   File "./app/__init__.py", line 8, in <module>
web  |     from flask_restplus import Api
web  |   File "/usr/local/lib/python3.6/site-packages/flask_restplus/__init__.py", line 4, in <module>
web  |     from . import fields, reqparse, apidoc, inputs, cors
web  |   File "/usr/local/lib/python3.6/site-packages/flask_restplus/fields.py", line 17, in <module>
web  |     from werkzeug import cached_property
web  | ImportError: cannot import name 'cached_property'
web  | unable to load app 0 (mountpoint='') (callable not found or import error)

issue on github: https://github.com/pallets/werkzeug/issues/2324

My requirements file (newest version of Werkzeug here):

Flask>=2.0.2
mysql-connector
mysqlclient
pyjwt>=2.0.0
datetime
Flask-SQLAlchemy==2.4.4
flask-login
werkzeug==2.0.3
flask-restplus==0.13.0
flask-marshmallow==0.14.0
marshmallow-sqlalchemy==0.24.1

I am wondering what are my options to get this application to work? I have never encountered a circular dependency issue such as this one. Thank you



Solution 1:[1]

With:

flask==1.1.2
werkzeug==1.0.1

it works well for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dudi709