Python3 ModuleNotFoundError: No module named ‘werkzeug.contrib‘ 今天药忘吃喽~ 2022-11-28 00:59 216阅读 0赞 from werkzeug.contrib.cache import SimpleCache 今天在执行上面这段代码时,Python解释器报错: ModuleNotFoundError: No module named 'werkzeug.contrib' 首先使用pip查看当前已安装`werkzeug`的信息: 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: armin.ronacher@active-4.com License: BSD-3-Clause Location: d:\python38\lib\site-packages Requires: Required-by: Flask 发现当前安装的`Werkzeug`版本为1.0.1,于是翻阅werkzeug的[官方文档][Link 1] **首先发现了这段话:** > **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) 意思是: **werkzeug.contrib已经在1.0版本被移除了!** 卧槽,那我要用的`cache`模块去哪了? 于是继续阅读文档发现了这段话: > **cache has been extracted into a separate project, cachelib. Theversion in Werkzeug is deprecated.** 原来`cache`现在已经变成了一个单独的项目,叫`cachelib`! 进行安装 pip install cachelib 测试 from cachelib import SimpleCache 噢!完全正常,看来只是因为版本升级导致模块找不到而已。 又可以继续写代码了…… [Link 1]: https://werkzeug.palletsprojects.com/en/1.0.x/changes/#version-1-0-1
还没有评论,来说两句吧...