When I import a Flask extension like this, it works fine:
from flask_module import Module
So the extension is installed correctly.
But whenever I try to import a Flask extension like this:
from flask.ext.module import Module
I get the following error: ImportError: No module named 'flask.ext'
What is going wrong here?
I'm not sure if this information is useful but anyway:
The Python "ModuleNotFoundError: No module named 'flask'" occurs when we forget to install the Flask module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install Flask command.
Flask – Extensions This is where the Flask extensions come in picture. Flask extensions give extensibility to Flask framework. There are a large number of Flask extensions available. A Flask extension is a Python module, which adds specific type of support to the Flask application.
Finding ExtensionsFlask extensions are listed on the Flask Extension Registry and can be downloaded with easy_install or pip. If you add a Flask extension as dependency to your requirements. txt or setup.py file they are usually installed with a simple command or when your application installs.
Jonatan Witoszek is indeed correct. I am a Flask enthusiast and so glad to see a standardization taking place. Most extensions are now in their own namespace rather than in the flask.ext namespace.
As for the suggestion that you install your flask packages globally, this somewhat defeats the purpose of using a venv in the first place. It makes it impossible to use pip freeze --local > requirements.txtto only save relevant packages, opening you up to package version conflicts.
The import error is occurring may be due to the virtual environment problem. You have to use the same virtual environment for any kind of operations with your web app. Try this: Now use your commands here i.e to install any module using pip or to start the Django/flask shell
I made a web server with Flask and python, and at one point I use Flask-Uploads. When I ran it, it worked originally, but when I moved it to another computer, it didn't work even though I installed all the packages correctly with pip. I have looked online for this error, and have found many solutions, but none of them work for me.
The "flask.ext" style of naming/importing modules has been deprecated for a number of years now. You should use the first style you described instead:
# Use this import format
from flask_sqlalchemy import SQLAlchemy
As for the suggestion that you install your flask packages globally, this somewhat defeats the purpose of using a venv in the first place. It makes it impossible to use pip freeze --local > requirements.txt
to only save relevant packages, opening you up to package version conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With