flask-cache icon indicating copy to clipboard operation
flask-cache copied to clipboard

ImportError: cannot import name 'import_string' from 'werkzeug'

Open aaronjolson opened this issue 4 years ago • 3 comments

I am trying to run my app, getting an error

ImportError: cannot import name 'import_string' from 'werkzeug'

The error is from

venv/lib/python3.7/site-packages/flask_cache/__init__.py", line 24, in <module>
    from werkzeug import import_string

I am running Python 3.7

pip freeze says Werkzeug==1.0.1 Flask==1.1.1 Flask-Cache==0.13.1 redis==3.5.3

Anyone else run into this error? Anyone know of a fix?

aaronjolson avatar Jul 23 '20 15:07 aaronjolson

For anyone stumbling into this issue, here is the quick'n dirty way to solve this:

# Monkeypatch to fix import in flask-cache
from werkzeug.utils import import_string
import werkzeug
werkzeug.import_string = import_string

import flask_cache  # Obviously flask_cache must be imported after the monkeypatch

touilleMan avatar Sep 14 '20 10:09 touilleMan

Or if you're like me and a bit tired, check your virtual env.

tuanardouin avatar Jul 13 '23 19:07 tuanardouin

@tuanardouin can you please add more on this?

chandukiran13 avatar Jul 13 '23 19:07 chandukiran13