Search code examples
python-3.xflaskflask-babel

ImportError: cannot import name 'locked_cached_property' from 'flask.helpers'


I've been trying to run a minimal flask app, just a hello world. I've instantiated Flask and Babel. Yet, I'm getting this error:

ImportError: cannot import name 'locked_cached_property' from 'flask.helpers'

I'm using flask v3.0.0, Flask-Babel 2.0.0 and werkzeug 3.0.1

Here's my code:

# app.py
#!/usr/bin/env python3
"""Basic Flask app"""
from flask import Config, Flask, render_template
from flask_babel import Babel

app = Flask(__name__)
babel = Babel(app)
app.config.from_object(Config)


@app.route("/")
def home():
    """Home page route"""
    return render_template("1-index.html")


if __name__ == "__main__":
    app.run(debug=True)

And:

# config.py
#!/usr/bin/env python3
"""Config class"""


class Config(object):
    """Flask configs"""

    LANGUAGES = ["en", "fr"]
    BABEL_DEFAULT_LOCALE = "en"
    BABEL_DEFAULT_TIMEZONE = "UTC"

I've tried various solutions involving cached_property, but I couldn't find any solutions related to locked_cached_property.

Note: One of the project requirements is that I must use flask-babel<3


Solution

  • The solution is to downgrade my Flask (Flask<3) in order to use Flask-Babel<3.