When using Flask-Script I get an error when importing Manager.
I have installed with pip Flask and Flask-Script. How do I fix this?
manage.py
from flask_script import Manager
from main import app
manager = Manager(app)
@manager.command
def hello():
print ("hello")
if __name__ == "__main__":
manager.run()
main.py
from flask import Flask
app = Flask(__name__)
Error
(venv) raul@raul-PC:~/Proyectos Python/flask_script$ python3 manage.py hello
Traceback (most recent call last):
File "manage.py", line 1, in <module>
from flask_script import Manager
File "/home/raul/Proyectos Python/flask_script/venv/lib/python3.8/site-packages/flask_script/__init__.py", line 15, in <module>
from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat'
To check which version of flask is installed, use pip show flask or pip3 show flask in your Windows CMD, command line, or PowerShell.
1 - I did installed modules manualy on PyCharm\settings\projet: myapp\python interpreter
by selecting my interpreter and installing libs missed like Flask
itself, flask-migrate
and flask-script
.
2 - On this specific error: from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat'
-
It happened because the python searched on Flask._compat
directory and It isn't there, so I changed like on below : (on flask_script/__init__.py
)
Where:
from ._compat import text_type
on original flask-script file
to :
from flask_script._compat import text_type
Then It works !!
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