Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import error in Jinja 2.10.x/2.11.x #1594

Closed
Nathanmalnoury opened this issue Feb 18, 2022 · 3 comments
Closed

Import error in Jinja 2.10.x/2.11.x #1594

Nathanmalnoury opened this issue Feb 18, 2022 · 3 comments

Comments

@Nathanmalnoury
Copy link

Nathanmalnoury commented Feb 18, 2022

Jinja 2.10.x installs the latest update of Markupsafe 2.1.0 released yesterday, which resolves in an ImportError.

This seems to be caused by the removal of soft_unicode from markupsafe in that version.

How to replicate:

In a terminal:

$ pip install Jinja2~=2.10.3 # same result with 2.11.x
$ python -c "import jinja2"

Traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/nathan/Project/jinja-bug/venv/lib/python3.8/site-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/home/nathan/Project/jinja-bug/venv/lib/python3.8/site-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/home/nathan/Project/jinja-bug/venv/lib/python3.8/site-packages/jinja2/nodes.py", line 19, in <module>
    from jinja2.utils import Markup
  File "/home/nathan/Project/jinja-bug/venv/lib/python3.8/site-packages/jinja2/utils.py", line 642, in <module>
    from markupsafe import Markup, escape, soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/nathan/Project/jinja-bug/venv/lib/python3.8/site-packages/markupsafe/__init__.py)

Note:

Installing the last MarkupSafe version before 2.1.0 fixes this issue:

$ pip install MarkupSafe~=2.0.0
$ pip install Jinja2~=2.10.3 
$ python -c "import jinja2"  # works

Environment:

  • Python version: 3.8.10
  • Jinja version: 2.10.x / 2.11.x
@Nathanmalnoury Nathanmalnoury changed the title Dependencies error in Jinja 2.10.x Import error in Jinja 2.10.x Feb 18, 2022
@Nathanmalnoury Nathanmalnoury changed the title Import error in Jinja 2.10.x Import error in Jinja 2.10.x/2.11.x Feb 18, 2022
@davidism
Copy link
Member

Duplicate of #1585

You are using an unsupported version of Jinja, please update to the latest version if possible. Additionally, please read https://hynek.me/articles/semver-will-not-save-you/, then use a tool like pip-tools to pin your dependencies and control when you get updates. Be sure to run your tests with deprecation warnings treated as errors so that you get notified of these types of changes early.

@vpogrebi
Copy link

Sorry... it's not clear from the comments - is this fix (to replace 'soft_unicode' with 'soft_str') coming? How soon?

@davidism
Copy link
Member

This is fixed in the supported versions of Jinja. Upgrade Jinja. Pin your dependencies with pip-tools or another dependency management tool to avoid unexpected updates in general.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants