Issue
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:
- I haven't found extensions that do work in the last way
- I use Windows 10, Python3.5 and Flask 1.0.2
- I'm in a virtual envirionment
Solution
The "flask.ext" style of naming/importing modules has been deprecated since 2016. Here's the reasoning. 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.
Answered By - Nick K9
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.