ImportError: cannot import name 'url_encode' from 'werkzeug'

ImportError: cannot import name 'url_encode' from 'werkzeug'

我目前 运行 是 flask-wtf version 0.14.2wtforms version 2.21 的 conda 环境,我无法解决这个 ImportError: cannot import name 'url_encode' from 'werkzeug'

以下代码是完整的回溯。

Traceback (most recent call last):
      File "run.py", line 1, in <module>
        from flaskblog import app
      File "/Users/justinding/Desktop/test/test_wesite/flaskblog/__init__.py", line 10, in <module>
        from flaskblog import routes
      File "/Users/justinding/Desktop/test/test_wesite/flaskblog/routes.py", line 4, in <module>
        from flaskblog.forms import RegistrationForm,LoginForm
      File "/Users/justinding/Desktop/test/test_wesite/flaskblog/forms.py", line 1, in <module>
        from flask_wtf import FlaskForm
      File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/__init__.py", line 17, in <module>
        from .recaptcha import *
      File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/__init__.py", line 2, in <module>
        from .fields import *
      File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/fields.py", line 3, in <module>
        from . import widgets
      File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/widgets.py", line 5, in <module>
        from werkzeug import url_encode
    ImportError: cannot import name 'url_encode' from 'werkzeug' (/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/werkzeug/__init__.py)

尝试从 werkzeug.urls

导入这个

在您的需求文件中设置 werkzeug==0.16.1 可以修复它。问题出在 1.0.0 版本

猜测错误与新版本的werkzeug有关。 在新的 werkzeug 版本中没有“url_encode”。 所以尝试安装旧版本的 werkzeug 像这样:"pip install werkzeug==0.16.0" 我用这个解决方案修复了