• flask-cache使用报错Python3 ModuleNotFoundError: No module named ‘werkzeug.contrib‘


    环境:

    Flask              2.1.2
    Flask-Cache        0.13.1
    Werkzeug           2.1.2

    问题:

    当使用了flask_cache时导致运行时问题出现:ModuleNotFoundError: No module named 'werkzeug.contrib'

    解决方式如下:

    1、修改文件/Users/zhangyanli/.pyenv/versions/flaskenv/lib/python3.7/site-packages/flask_cache/__init__.py。将上一行改为下一行

    1. # from werkzeug import import_string
    2. from werkzeug.utils import import_string

    【备注】这个修改是为了解决如下报错ImportError: cannot import name 'import_string' from 'werkzeug' (/Users/zhangyanli/.pyenv/versions/flaskenv/lib/python3.7/site-packages/werkzeug/__init__.py)


    2、修改文件/Users/zhangyanli/.pyenv/versions/flaskenv/lib/python3.7/site-packages/flask_cache/jinja2ext.py。将上一行改为下一行

    1. # from flask.ext.cache import make_template_fragment_key
    2. from flask_cache import make_template_fragment_key

    3、安装cachelib 

    pip install cachelib

    【备注】werkzeug.contrib已经在1.0版本被移除了,所以无法从werkzeug.contrib.cache 中导入,需要单独安装cachelib

     4、修改文件/Users/zhangyanli/.pyenv/versions/flaskenv/lib/python3.7/site-packages/flask_cache/backends.py。将上一行改为下一行

    1. # from werkzeug.contrib.cache import (BaseCache, NullCache, SimpleCache, MemcachedCache,GAEMemcachedCache, FileSystemCache)
    2. from cachelib import (BaseCache, NullCache, SimpleCache, MemcachedCache, FileSystemCache)

  • 相关阅读:
    postgres in (?,?) 和 =any(?) 用法/性能对比
    常用H标签的补充:html5
    vue如何使用深度选择器?
    算法&数据结构 - 栈相关基础概念
    【kafka】 查看节点的消息
    乔迁之喜!泛微软件园启用,欢迎新老朋友来坐坐
    Redisson实现延迟队列
    如何搭建属于自己的查题公众号?
    [python 刷题] 242 Valid Anagram
    typeof的作用
  • 原文地址:https://blog.csdn.net/Li_Vampire_123/article/details/132671396