Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am currently running a conda environment with flask-wtf version 0.14.2 and wtforms version 2.21 and I have trouble solving this ImportError: cannot import name 'url_encode' from 'werkzeug'

The following code is the complete traceback.

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)
like image 664
Justin Ding Avatar asked Mar 28 '20 03:03

Justin Ding


3 Answers

Setting werkzeug==0.16.1 in your requirements file fixes it. The issue is with the 1.0.0 version

like image 116
PILA Avatar answered Oct 13 '22 14:10

PILA


guess the error is related to the new version of werkzeug. in new werkzeug version there is no "url_encode'. so try to install an older version of werkzeug like this : "pip install werkzeug==0.16.0" mine fixed with this solution

like image 21
sina sheikhzahed Avatar answered Oct 13 '22 15:10

sina sheikhzahed


try to import this from werkzeug.urls

like image 11
zo0M Avatar answered Oct 13 '22 14:10

zo0M