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
Related
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
I'm writing a script which will build the docker image and then push the image to ECR.
my current python version is
>python --version
Python 3.8.0
so, for some reason, at the first line while running my python at local, I'm getting below error. Saying this means, it has not yet build the image to push into the ECR.
import docker --> throws below error
Traceback (most recent call last):
File "genericECR.py", line 1, in <module>
import docker
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\docker\__init__.py", line 2, in <module>
from .api import APIClient
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\docker\api\__init__.py", line 2, in <module>
from .client import APIClient
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\docker\api\client.py", line 8, in <module>
import websocket
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websocket\__init__.py", line 23, in <module>
from ._app import WebSocketApp
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websocket\_app.py", line 36, in <module>
from ._core import WebSocket, getdefaulttimeout
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websocket\_core.py", line 34, in <module>
from ._handshake import *
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websocket\_handshake.py", line 40, in <module>
if six.PY34:
AttributeError: module 'six' has no attribute 'PY34'
six is already installed
Requirement already satisfied: six in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (1.6.1)
it seems like it is intended for python 34 so for python 38, how can I solve this?
Most probably the six version is not high enough, c.f. https://github.com/docker/docker-py/issues/2294
First check the six version:
import six
print(six.__version__)
If six version is not >=1.0.0, then upgrade six, on command line
python -m pip install -U six
With the latest pip, you should see this:
>>> import six
>>> six.__version__
'1.13.0'
>>> six.PY34
True
it helped, I was having the issue with docker-compose running, that command helped:
python -m pip install -U six
aks.py:
from twilio.rest import Client
When execute above code, I am getting the error:
Traceback (most recent call last):
File "aks.py", line 10, in <module>
from twilio.rest import Client
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/__init__.py", line 14, in <module>
from twilio.http.http_client import TwilioHttpClient
File "/usr/local/lib/python2.7/dist-packages/twilio/http/http_client.py", line 1, in <module>
from requests import Request, Session, hooks
File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 24, in <module>
from ._internal_utils import to_native_string
File "/usr/lib/python2.7/dist-packages/requests/_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 46, in <module>
from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict
I tried various things like degrading Urllib to 1.23, uninstal, reinstall twilio and sudo -H pip2.7 install twilio
python version: Python 2.7.13
pip version: pip 18.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
OS : Raspbian Stretch
One of my project dependencies "google-endpoints", depends on "Google Endpoints API Management", which depends on requests and requests depends on urllib3, however the post installed urllib3==1.24 is not supported by requests.
This issue can be solved with installing the previous stable version of urllib3:
pip install urllib3==1.23
INSTALLED_APPS = [ 'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','orders','products', 'profiles', ]I have same issue. Please go and check in settings installed apps. weather your app exists in settings portion
I solved it by making a virtual environment of python 3 and it works properly.
I think for some reason twilio don't work properly on python 2.7
I have set up an all in one swift. While setting up keystone in all-in-one-swift I am having an error when I try to create the service entity and API endpoints. I followed liberty documentation but couldn't resolve this issue!
Documentation link
[root#arupsaio ~]# openstack service create --name keystone --description "OpenStack Identity" identity
Traceback (most recent call last):
File "/usr/bin/openstack", line 6, in <module>
from openstackclient.shell import main
File "/usr/lib/python2.7/site-packages/openstackclient/shell.py", line 30, in <module>
from openstackclient.common import clientmanager
File "/usr/lib/python2.7/site-packages/openstackclient/common/clientmanager.py", line 23, in <module>
import requests
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in <module>
from .exceptions import InvalidURL, FileModeWarning
ImportError: cannot import name FileModeWarning
In my case, there were some package leftovers.
I had to uninstall the package 3 times!
pip uninstall requests # x3
And then reinstall the new version
pip install requests
While trying to make attempt of installing it i get following error. What am I missing?
Install packages failed: Error occurred when installing package Flask-SQLAlchemy.
The following command was executed:
packaging_tool.py install --build-dir /private/var/folders/4B/4Bd6e77uH-uNGxBS-xhds++++TI/-Tmp-/pycharm-packaging5175396548329498703.tmp Flask-SQLAlchemy
The error output of the command:
Error: Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/packaging_tool.py", line 54, in do_install
import pip
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/util.py", line 18, in <module>
from pip._vendor.distlib import version
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/version.py", line 14, in <module>
from .compat import string_types
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/compat.py", line 31, in <module>
from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler
Here is the SO question got several answers Python ImportError: cannot import name HTTPSHandler.
Which in general, check if you have ssl module, and OpenSSL header files installed.