Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'flask.ext' [duplicate]

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:

  1. I haven't found extensions that do work in the last way
  2. I use Windows 10, Python3.5 and Flask 1.0.2
  3. I'm in a virtual envirionment
like image 316
Lewistrick Avatar asked Mar 06 '19 12:03

Lewistrick


People also ask

Why is there no module named flask?

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.

What is flask ext?

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.

How do you install a flask extension?

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.

Are flask extensions now in their own namespace?

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.

Should I install all my flask packages globally?

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.

How do I fix import error in Django?

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

Does flask-uploads work on another computer?

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.


Video Answer


1 Answers

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.

like image 102
Nick K9 Avatar answered Oct 19 '22 11:10

Nick K9