Python3 ModuleNotFoundError: No module named ‘werkzeug.contrib‘

from werkzeug.contrib.cache import SimpleCache

When executing the above code today, the Python interpreter reported an error:

ModuleNotFoundError: No module named 'werkzeug.contrib'

First use pip to view the currently installed werkzeuginformation:

pip show werkzeug
Name: Werkzeug
Version: 1.0.1
Summary: The comprehensive WSGI web application library.
Home-page: https://palletsprojects.com/p/werkzeug/
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: d:\python38\lib\site-packages
Requires:
Required-by: Flask

Found that the currently installed Werkzeugversion is 1.0.1, so I read the official documentation of werkzeug

First discovered this passage:

The contrib modules are deprecated and will either be moved into werkzeug core or removed completely in version 1.0.
Some modules that already issued deprecation warnings have been removed.
Be sure to run or test your code with python -W default::DeprecationWarning to catch any deprecated code you’re using. (#4)

Means: werkzeug.contrib has been removed in version 1.0!

Damn, where is the cachemodule I want to use ?

So continue reading the document and found this passage:

cache has been extracted into a separate project, cachelib. Theversion in Werkzeug is deprecated.

It cacheturned out to be a separate project now, called cachelib!

To install

pip install cachelib

test

from cachelib import SimpleCache

Oh! It is completely normal, it seems that the module cannot be found because of the version upgrade.

You can continue to write code...

Guess you like

Origin blog.csdn.net/qq_26373925/article/details/108045684