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

We Are Going To Discuss About ImportError: cannot import name ‘Markup’ from ‘jinja2’. So lets Start this Python Article.

ImportError: cannot import name ‘Markup’ from ‘jinja2’

  1. [Solved] ImportError: cannot import name 'Markup' from 'jinja2'

    Fixed calling deprecated jinja2.Markup without an argument. Use markupsafe.Markup instead. #1438

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

    Fixed calling deprecated jinja2.Markup without an argument. Use markupsafe.Markup instead. #1438

Solution 1

Version 3.0.1

Regarding to the documentation

Fixed calling deprecated jinja2.Markup without an argument. Use markupsafe.Markup instead. #1438

So to import Markup use the following code :

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

Original Author Ged Flod Of This Content

Solution 2

As the import error comes from flask File "/usr/local/lib/python3.7/site-packages/flask/__init__.py

I tried to create a new Flask application using Flask==1.0.2 and found that the error comes from this version of Flask when it used with Jinja2>=2.10.1.

But when you remove Flask==1.0.2 and install Flask==2.0.3, everything works fine.

pip uninstall  Flask Jinja2
pip install Flask Jinja2

Dependencies

pip freeze
click==8.0.4
Flask==2.0.3
itsdangerous==2.1.2
Jinja2==3.1.1
MarkupSafe==2.1.1
Werkzeug==2.0.3

Original Author Ged Flod Of This Content

Solution 3

The actual version of jinja is 3.x try to update jinja:

  1. Uninstall Jinja2==2.10.1
pip uninstall jinja2
  1. Install the latest version of jinja2
pip install --upgrade jinja2

Original Author Ged Flod Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment