Python3 flask 依赖包 werkzeug 报错 ImportError

pipPython 中超级好用的包管理工具,但是 pip 会不定时更新

WARNING: You are using pip version 19.3.1; however, version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

提示已经很明显了,我们使用 upgrade 更新我们的 pip

pip install --upgrade pip

但是更新完以后就郁闷了,之前的项目启动不起来了。。。

Traceback (most recent call last):
  File "/Users/zhangyi/Documents/crm/manage.py", line 7, in <module>
    from app.urls import blueprint
  File "/Users/zhangyi/Documents/crm/app/urls.py", line 5, in <module>
    from flask_restplus import Api
  File "/Users/zhangyi/.virtualenvs/crm_user_service/lib/python3.8/site-packages/flask_restplus/__init__.py", line 4, in <module>
    from . import fields, reqparse, apidoc, inputs, cors
  File "/Users/zhangyi/.virtualenvs/crm_user_service/lib/python3.8/site-packages/flask_restplus/fields.py", line 17, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/Users/zhangyi/.virtualenvs/crm_user_service/lib/python3.8/site-packages/werkzeug/__init__.py)

根据报错,我们知道是因为导入 werkzeug 包时报错。。。

作为一个“面向谷歌编程”的程序员,查询后得知这是因为 werkzeug 新版本里需要显式导入该模块

所以我没找到它的包路径

/Users/zhangyi/.virtualenvs/crm_user_service/lib/python3.8/site-packages/werkzeug/__init__.py

添加一行

from werkzeug.utils import cached_property

即可

发布了356 篇原创文章 · 获赞 315 · 访问量 124万+

猜你喜欢

转载自blog.csdn.net/yilovexing/article/details/104972617