thadeusb / flask-cache

Cache extension for Flask
http://packages.python.org/Flask-Cache/
Other
697 stars 185 forks source link

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

Open aaronjolson opened 4 years ago

aaronjolson commented 4 years ago

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?

touilleMan commented 4 years ago

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
tuanardouin commented 1 year ago

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

chandukiran13 commented 1 year ago

@tuanardouin can you please add more on this?