close

[Solved] ImportError: cannot import name ‘Markup’ from ‘jinja2’

I am using Jinja2 with Flask But Somehow I am facing the following error ImportError: cannot import name ‘Markup’ from ‘jinja2’ in Python. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.

How This Error Occurs?

I am using Jinja2 with Flask But Somehow I am facing the following error:

ImportError: cannot import name 'Markup' from 'jinja2'

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve ImportError: cannot import name ‘Markup’ from ‘jinja2’ Error?

  1. How To Solve ImportError: cannot import name 'Markup' from 'jinja2' Error?

    To Solve ImportError: cannot import name 'Markup' from 'jinja2' Error You need to Use Flask==2.0.3 and Jinja2==3.1.1 to work fine. So Just run this command: pip install Flask==2.0.3 and pip install Jinja2==3.1.1 Now, your error will be solved.

  2. ImportError: cannot import name 'Markup' from 'jinja2'

    To Solve ImportError: cannot import name 'Markup' from 'jinja2' Error You need to import Markup just like this: from jinja2.utils import markupsafe markupsafe.Markup() Markup('') Now, Your error must be solved.

Solution 1: Import Markup Just like this

You need to import Markup just like this.

from jinja2.utils import markupsafe 
markupsafe.Markup()
Markup('')

Now, Your error must be solved.

Solution 2: Use This versions

You need to Use Flask==2.0.3 and Jinja2==3.1.1 to work fine. So Just run this command.

pip install Flask==2.0.3

and

pip install Jinja2==3.1.1

Now, your error will be solved.

Summary

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

2 thoughts on “[Solved] ImportError: cannot import name ‘Markup’ from ‘jinja2’”

Leave a Comment