Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I do Flask run, it shows error : ModuleNotFoundError: No module named 'werkzeug.contrib'. Can anyone help me with this?

the exact error I get is :

flask.cli.NoAppException: While importing "application", an ImportError was raised:Traceback      (most recent call last):
File "/home/harshit/.local/lib/python3.6/site-packages/flask/cli.py", line 240, in     locate_app
__import__(module_name)
File "/home/harshit/Documents/project1/application.py", line 18, in <module>
Session(app)
File "/home/harshit/.local/lib/python3.6/site-packages/flask_session/__init__.py", line 54,    in __init__
self.init_app(app)
File "/home/harshit/.local/lib/python3.6/site-packages/flask_session/__init__.py", line 61, in init_app
app.session_interface = self._get_interface(app)
File "/home/harshit/.local/lib/python3.6/site-packages/flask_session/__init__.py", line 93, in _get_interface
config['SESSION_USE_SIGNER'], config['SESSION_PERMANENT'])
File "/home/harshit/.local/lib/python3.6/site-packages/flask_session/sessions.py", line 313, in __init__
from werkzeug.contrib.cache import FileSystemCache
ModuleNotFoundError: No module named 'werkzeug.contrib'

I am trying to import sessions from Flask

like image 885
Harshit Avatar asked Mar 10 '20 18:03

Harshit


3 Answers

Either downgrade the version to 0.16.0 or replace werkzeug.contrib.cache with cachelib.

I can highly recommend upgrading the package. The deprecated module werkzeug.contrib is very easy to replace!

Install cachelib and replace all imports from:

from werkzeug.contrib.cache import FileSystemCache

to

from cachelib import FileSystemCache
like image 133
Stephan Schielke Avatar answered Sep 23 '22 00:09

Stephan Schielke


Werkzeug 1.0.0 has removed deprecated code, including all of werkzeug.contrib. You should use alternative libraries for new projects. werkzeug.contrib.session was extracted to secure-cookie.


If an existing project you're using needs something from contrib, you'll need to downgrade to Werkzeug<1:

pip3 install Werkzeug<1
like image 19
Aleksey Avatar answered Nov 14 '22 08:11

Aleksey


You will need to downgrade werkzeug version from 1.0.0 to 0.16.0

This solved the problem for me.

Just run the following commands in your project:

python3 -m pip uninstall werkzeug

and then

python3 -m pip install werkzeug==0.16.0

like image 5
Asad Khan Avatar answered Nov 14 '22 08:11

Asad Khan