. Advertisement .
..3..
. Advertisement .
..4..
Python is an object-oriented programming language with a high level of abstraction. This language is used to create a variety of applications and websites. Python is the perfect choice for top professionals to beginners, thanks to its simple yet elegant structure. This language is also appreciated for its rigor, power, and speed, which are present in all operating systems. When you try to complete your task, you get this error: “flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python“. This error is one of the most popular errors any programmer will make. So, why does it appear, and how can it be resolved? We’ll go over it with you.
Why Does The Error: flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python Occur?
You are working with Flask-Script. When you try to import Manager, you get an error. You have installed Flask and Flask-Script by using pip.
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'
You have got the error ”flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python” because Python found Flask._compat in the Flask._compat directory but it was not there.
The Effective Methods For ” flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python” error
Solution 1: Degrade the Flask
If you upgrade Flask to version 2.0.0, you should downgrade to version 1.1.2 to make it work. You can also use the following commands instead of Flask-Script.
flask db init # to initialize the database
flask db migrate # to migrate new changes
flask db upgrade # to upgrade and so on.
Solution 2: Use the Flask 1.1.4
In this method, you need to install Flask 1.1.4 and the werkzeug. You can use these codes.
pip install "Flask==1.1.4"
pip install "werkzeug==1.0.1"
We believe that the above method will be beneficial to all of you.
Solution 3: Change as the following
Besides two above mentioned solutions, there is another way to resolve the ” flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python” error. Based on the reason Python found Flask._compat in its directory but it does not exist there, so you can change as the following: (on flask_script/init.py).
From
from ._compat import text_type
It is on the initial file of flask-script.
To
from flask_script._compat import text_type
After you do that, your error will be fixed. Although this solution is simple, its efficiency is very enormous. Let’s do it.
Conclusion
The solutions mentioned above are the best options for those still confused with this error: “flask._compat import text_type ModuleNotFoundError: No module named ‘flask._compat’ in Python“. If you need our support or have other questions, we have a thriving community where everyone is always willing to help. Finally, we wish you a productive day filled with new solutions and code.
Read more
→ Tips On Solving The Error: “ModuleNotFoundError: No module named ‘wtforms.compat’”
Leave a comment