python ImportError:无法从“werkzeug”导入名称“url_encode”

vfwfrxfs  于 2023-05-05  发布在  Python
关注(0)|答案(4)|浏览(664)

我目前正在运行一个包含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)
ohfgkhjo

ohfgkhjo1#

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

2vuwiymt

2vuwiymt2#

我猜这个错误与werkzeug的新版本有关。在新werkzeug版本中,没有“url_encode”。所以尝试安装一个旧版本的werkzeug如下:“pip install werkzeug==0.16.0”mine已使用此解决方案修复

ymzxtsji

ymzxtsji3#

尝试从werkzeug.urls导入

aiazj4mn

aiazj4mn4#

使用Below语法
从werkzeug.urls导入url_encode

相关问题