转自:noerror.net
ImportError: cannot import name 'parse_rule' from 'werkzeug.routing' 解决办法 问题描述 当在其他系统上运行Flask工程时报错: Error: While importing 'app', an ImportError was raised: Traceback (most recent call last): File "c:\users\User\appdata\local\programs\python\python39\lib\site-packages\flask\cli.py", line 214, in locate_app __import__(module_name) File "C:\Users\User\Desktop\Projekt\app\__init__.py", line 3, infrom flask_restx import Namespace, Api File "c:\users\User\appdata\local\programs\python\python39\lib\site-packages\flask_restx\__init__.py", line 5, in File "c:\users\User\appdata\local\programs\python\python39\lib\site-packages\flask_restx\api.py", line 50, in from .swagger import Swagger File "c:\users\User\appdata\local\programs\python\python39\lib\site-packages\flask_restx\swagger.py", line 18, in from werkzeug.routing import parse_rule ImportError: cannot import name 'parse_rule' from 'werkzeug.routing' (c:\users\User\appdata\local\programs\python\python39\lib\site-packages\werkzeug\routing\__i nit__.py) 工程依赖配置: Flask~=2.1.2 psycopg2-binary==2.9.3 Flask-SQLAlchemy==2.5.1 flask-restx==0.5.1 qrcode~=7.3.1 PyPDF2==2.6.0 reportlab~=3.6.10 WTForms~=3.0.1 flask-bootstrap==3.3.7.1 flask-wtf==1.0.1 解决办法 在requirements.txt中添加: werkzeug==2.1.2 根因分析 这是由于 parse_rule() 在最新版本的 werkzeug 上被标记为 :internal: 引起的,这会影响 flask-restx(以及许多其他功能,例如 flask-login)。 参考: https://github.com/maxcountryman/flask-login/issues/686 https://github.com/python-restx/flask-restx/issues/460