Skip to content
Home » ModuleNotFoundError: No module named ‘flask._compat’

ModuleNotFoundError: No module named ‘flask._compat’

To solve ModuleNotFoundError: No module named ‘flask._compat’ error follow below methods.

ERROR LOG

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 Solve flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ Error follow the below steps.

How to solve ModuleNotFoundError: No module named ‘flask._compat’ ?

If you upgraded Flask to version 2.0.0, you should downgrade to version 1.1.2 and it will work. You can also use the following instructions instead of Flask-Script.

EDIT
Instead of using with Flask-Script, you can simply use the below commands :

flask db init to initialize the database
flask db migrate to migrate new changes
flask db upgrade to upgrade and so on.

Alternative to Solve ModuleNotFoundError: No module named ‘flask._compat’

Installed Flask 1.1.4

pip install "Flask==1.1.4"

And also werkzeug

pip install "werkzeug==1.0.1"

Other Solution

  1. I manually installed modules on PyCharm settings project: myapppython interpreter by selecting my interpreter and installing missing libs such as Flask itself, flask-migrate, and flask-script.
  2. Regarding this exact error: import text type from flask. compat ModuleNotFoundError: No module named ‘flask. compat’ –

It happened because Python looked in the Flask._compat directory and it wasn’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

Hope the above solution works.

Also read :

No module named pyLDAvis
Error: (this.configurationService.getValue(…) || []).filter is not a function in VS Code