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)
Setting werkzeug==0.16.1 in your requirements file fixes it. The issue is with the 1.0.0 version
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
try to import this from werkzeug.urls
Related
I've got an issue when I want to init my Flask DB, here is Terminal result :
user#Pc:~/Documents/test$ flask db init
Traceback (most recent call last):
File "/home/user/.local/bin/flask", line 7, in <module>
from flask.cli import main
File "/home/user/.local/lib/python3.6/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/__init__.py", line 151, in <module>
__import__('werkzeug.exceptions')
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/__init__.py", line 30, in <module>
from .request import PlainRequest
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/request.py", line 6, in <module>
from .user_agent import UserAgentMixin
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/user_agent.py", line 1, in <module>
from ..useragents import UserAgent
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/useragents.py", line 212, in <module>
from werkzeug.wrappers import UserAgentMixin # noqa
ImportError: cannot import name 'UserAgentMixin'
I'm working on an Ubuntu 18.04 LTS, using Flask, SQLAlchemy, Python and PostgreSQL. From where does this error occurs, and how can I solve it?
P.S : I followed the mega tutorial about Flask
EDIT 1 : Werkzeug is already installed
(venv) user#Pc:~/Documents/test$ pip install Werkzeug
Requirement already satisfied: Werkzeug in ./venv/lib/python3.6/site-packages
EDIT 2 : I don't know why I got this issue, but this error disappear after I removed spaces indentations
Try pip install Werkzeug
UserAgentMixin is from werkzeug!
ref: https://tedboy.github.io/flask/generated/generated/werkzeug.UserAgentMixin.html
in my case, I found a file and a folder, both named "wrappers" in the package path, so I reinstall the package:
pip uninstall Werkzeug
pip install Werkzeug
though a little late, it may still help
python version is 3.6.6 and pandas_datareader version is 0.7.0
when i import pandas_datareader, an error occurs like below.
C:\PycharmProjects\Demo\venv\Scripts\python.exe C:/PycharmProjects/Demo/stock.py
Traceback (most recent call last):
File "C:/PycharmProjects/Demo/stock.py", line 3, in <module>
import pandas_datareader as wb
File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\base.py", line 11, in <module>
from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'
can somebody help me?
The problem is pandas 0.25.0 has removed pandas.compat. So go back to 0.24.2
pip install "pandas<0.25.0"
or
pipenv install "pandas<0.25.0"
I ran into the same issue with Python3.6 and Python3.7
Downgraded, and it works fine on Python2.7
Also, saw a comment above that Python3.5 works.
I am trying to import pyLDAvis but it gives the error ModuleNotFoundError: No module named '_contextvars' although I installed both pyLDAvis and contextvars. The error is as follows
Traceback (most recent call last):
File "C:/Users/ebru/Documents/Arda Docs/Mydocs/ITLS/Research/Tüpraş/Python Codes/Tupras_NLPv04.py", line 249, in <module>
import pyLDAvis
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\pyLDAvis\__init__.py", line 44, in <module>
from ._display import *
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\pyLDAvis\_display.py", line 7, in <module>
import jinja2
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\__init__.py", line 82, in <module>
_patch_async()
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\asyncsupport.py", line 13, in <module>
import asyncio
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 39, in <module>
from . import events
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\events.py", line 14, in <module>
import contextvars
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
I tried to delete the underscore in contextvars.py but it did not work.
Plotting tools
import pyLDAvis
import pyLDAvis.sklearn
According to https://github.com/axnsan12/drf-yasg/issues/362#issuecomment-494360308, this problem might result from virtualenv not upgrading to the Python version you have installed.
Also, 3.7.4 has been released & includes changes related to Context Variables. Maybe upgrading to that helps?
This is the hints,how can I resolve it?
I use Python 3.5.1 created a virtual envirement by virtualenv
The source code works well on my friend's computer machine
Error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "A:\Python3.5\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "A:\Python3.5\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "A:\Python3.5\lib\site-packages\django\__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "A:\Python3.5\lib\site-packages\django\utils\log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "A:\Python3.5\lib\site-packages\django\views\debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "A:\Python3.5\lib\site-packages\django\http\__init__.py", line 4, in <module>
from django.http.response import (
File "A:\Python3.5\lib\site-packages\django\http\response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "A:\Python3.5\lib\site-packages\django\core\serializers\__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "A:\Python3.5\lib\site-packages\django\core\serializers\base.py", line 6, in <module>
from django.db import models
File "A:\Python3.5\lib\site-packages\django\db\models\__init__.py", line 6, in <module>
from django.db.models.query import Q, QuerySet, Prefetch # NOQA
File "A:\Python3.5\lib\site-packages\django\db\models\query.py", line 13, in <module>
from django.db.models.fields import AutoField, Empty
File "A:\Python3.5\lib\site-packages\django\db\models\fields\__init__.py", line 18, in <module>
from django import forms
File "A:\Python3.5\lib\site-packages\django\forms\__init__.py", line 6, in <module>
from django.forms.fields import * # NOQA
File "A:\Python3.5\lib\site-packages\django\forms\fields.py", line 18, in <module>
from django.forms.utils import from_current_timezone, to_current_timezone
File "A:\Python3.5\lib\site-packages\django\forms\utils.py", line 15, in <module>
from django.utils.html import format_html, format_html_join, escape
File "A:\Python3.5\lib\site-packages\django\utils\html.py", line 16, in <module>
from .html_parser import HTMLParser, HTMLParseError
File "A:\Python3.5\lib\site-packages\django\utils\html_parser.py", line 12, in <module>
HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'
As you can read here this error is raised...
because HTMLParseError is deprecated from Python 3.3 onwards and removed in Python 3.5.
What you can do is downgrade your Python version or upgrade your Django version.
I've just got the same error here. The Django version installed on my machine was 1.7.
Upgrading to Django 1.8.* solved the problem for me.
You can upgrade your Django using following command:
If you are using pip3:
sudo pip3 install django --upgrade
If pip:
sudo pip install django --upgrade
pip install Django --upgrade
python manage.py runserver
I have the most updated numpy, httplib2, pytz, Cython, python-dateutil & numexpr
And newest pandas build
But I'm flummoxed! The following code gives the following rather cryptic error. What is it trying to tell me?
import pandas
print "ok pandas"
error:
Traceback (most recent call last):
File "sank.py", line 1, in <module>
import pandas
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/__init__.py", line 45, in <module>
from pandas.io.api import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/io/api.py", line 15, in <module>
from pandas.io.gbq import read_gbq
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/io/gbq.py", line 59, in <module>
import httplib2
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1070, in <module>
from google.appengine.api import apiproxy_stub_map
File "/Users/maggielee/Documents/pythons/google.py", line 32, in <module>
GET / HTTP/1.0
NameError: name 'GET' is not defined
Solution by furas and OP.
I had an old file called google.py. Just renamed/deleted it and problem was solved.
Probably python uses this file when it imports from google.appengine.api.