Can't import flask because werkzeug - python

When I use from flask import *, I get the error
ImportError: No module named werkzeug.exceptions
However, when I do pip freeze, I can see that Werkzeug==0.11.11 is indeed installed. How can I fix this?

I am asumming, that the wrong version of Werkzeug was installed in the fist place. This usually happens, when you have 2 versions of python installed, and you use 'pip' for installing dependancies rather than using 'pip3'. Hope this helped!

I had this problem with Yocto while installing python-flask from: http://git.yoctoproject.org/git/meta-virtualization.
The solution was to manually add python-werkzeug to my yocto image as well. I suspect that python-flask should depend upon python-werkzeug. Additionally, I had to add python-jinja2 as well to the image.

I faced same issue.
I got this error when working in python virtual environment.
I had to deactivate virtual environment. Then go to root user and install werkzeug using pip. After that it works in virtual environment.

I had installed quite a few flask packages only with pip, but that was not enough, I also got the error ImportError: No module named werkzeug.exceptions.
The hint of the other answer, mentioning python-flask and python-werkzeug, brought the main idea. In my case, the solution was to apt-get install python-flask. It installed werkzeug as a dependency and the error was gone.

Related

Pip installed a module I want to use, but still getting "module not found" error

I am trying to use the Python module Gdal. I have run pip install gdal and I recieve the message
Requirement already satisfied: gdal in c:\users\willy\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (3.3.1)
and yet when I run import gdal in my Python IDE (I use Spyder), I still get the error no module named gdal
You need to tell Spyder which Python interpreter to use. Point it to the one you're installing the package for, as it seems that it's using a different one.
https://docs.spyder-ide.org/current/faq.html#using-existing-environment
From the documentation it seems you have to call:
from osgeo import gdal
See here
Answer is here in Spyder docs: https://docs.spyder-ide.org/5/faq.html#using-packages-installer
Don't try to use pip install and expect it to work in Spyder. Follow these instructions

Having issue importing requests and I assume it's my python runtime not being set correctly

Probably stupidly I tried to install the latest version of Python, in this case using the download from python site, but after doing that I was then getting python still running on the previous version python-3.6. I'm on OSX and was using sublime.
So I have been trying to work out how to update it to use the newest version. I've followed; https://opensource.com/article/19/5/python-3-default-mac.
All of the responses to queries now point to the python-3.9.5 version. So that's great and my runtime is using that. However after installing the requests using pip install I get the following error when running.
import requests
ModuleNotFoundError: No module named 'requests'''
[path: /Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
I stumbled upon Modules are installed using pip on OSX but not found when importing which I have been trying to work through.
I have been able to run the import command successfully in terminal, however it's intermittent as I've tried again and it's broken, so I'm lost. I'm running it something trying to run the python3.6 version, which after updating I followed these instructions to remove when I have uninstalled that from my mac https://www.macupdate.com/app/mac/5880/python/uninstall.
If there is any ideas, would love some help, mainly to try and tell me what that error message is telling me.
In particular, what does this mean?
[path: /Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.6/
I should clarify too; when I run 'pip list'
I see
requests 2.25.1
Assuming that you are not installing requests package properly, and assuming your python executable is named python:
python -m pip install requests
If however, your python executable is named something else instead, e.g. python3, replace python with that name:
python3 -m pip install requests

Python 3.7 cmath module import error

i installed python3.7 on ubuntu using ppa:deadsnakes/ppa repository.
When I try to run
import cmath
in python shell it fails with message:
ModuleNotFoundError: No module named 'cmath'
I didn't find any info about depracation of this library or anything in python3.7 changelog. It works fine in pythons 3.5 and 2.7. I tried installing it on different ubuntu virtual machines and computers and I always get the same result.
Do I need to install some specific library or something (which I doubt because the module is listed in standard library https://docs.python.org/3/library/index.html) or is problem elsewhere?
This was a bug in the deadsnakes backport of python3.7 specifically for xenial.
During the 3.7 beta period (when the package was imported). The cpython build system used PY_CORE_CFLAGS as a make variable. It was later changed to PY_STDMODULE_CFLAGS. debian ships a patch with their package that adjusts a generated makefile line using a sed expression for that specific variable. Since this was missing it caused the cmath module to build incorrectly.
This has been fixed in this commit
This fix is available in 3.7.0-1+xenial2 (debian version)
I installed python3.7 by downloading and installing it using make and cmath started working. It looks like ppa:deadsnakes/ppa repository had missing cmath module.

Cannot import six.python_2_unicode_compatible in Django application

Due a new requirement on my Django app, I started using zeep. I installed it as usual throught an existing virtualenv.
The problem is that, when i tried to deploy my app, using Apache and mod_wsgi, it doesn't work, returning the following error:
ImportError at /prwn/
cannot import name python_2_unicode_compatible
/home/prwn/env/lib/python2.7/site-packages/zeep/wsdl/definitions.py in <module>
from six import python_2_unicode_compatible
The weirdest thing is that when my app is ran using runserver and the same virtualenv, it runs fine.
I tried creating a new virtualenv, a new Apache's virtualhost, even changing the permisions to 777 to the whole virtualenv,
and still not working.
I use the versions 0.23.0 of zeep, 1.10.0 of six and python 2.7
Well, at the end i figured it out. Oddly, when my app was running with Apache, it used the old version of the six library, wich was installed globally on my system.
I solved it upgrading the global six library to the new version, and it worked.
solved it using 'pip install --upgrade six'
this is because of the older version of six < 1.9.0

ImportError: No module named twilio.rest

I realize this question has been posted before (1, 2), but none of the posted solutions have worked for me.
I've correctly installed twilio in python 2.7.0 using pip install
I've checked to make sure none of the projects are named twilio.py
I've tried uninstalling and re-installing, confirmed twilio version 5.7.0
tried relaunching IDLE
I'm still getting the "ImportError: No module named twilio.rest" message. What can I do?
You need to make sure that your pip command that you are running is from the right path, just as described in their FAQ
This one worked for me:
/usr/local/bin/pip install twilio

Categories