Skip to content

Jinja 2 imports have been deprecated #10291

Closed

Description

@jontwo

Describe the bug

There is an ImportError when using Sphinx with the latest version of Jinja2.

How to Reproduce

On any project:

$ pip install -U jinja2
$ make html

You get the error:

  File "/builds/venv/lib/python3.8/site-packages/sphinx/util/rst.py", line 21, in <module>
    from jinja2 import Environment, environmentfilter
ImportError: cannot import name 'environmentfilter' from 'jinja2' (/builds/venv/lib/python3.8/site-packages/jinja2/__init__.py)

Expected behavior

Sphinx builds without error.

Your project

This will work on any project

Screenshots

No response

OS

Rocky Linux 8.5

Python version

3.8.8

Sphinx version

3.5.4

Sphinx extensions

No response

Extra tools

No response

Additional context

No response

Activity

  1. ViktorHaag commented on Mar 24, 2022

    @ViktorHaag
    Contributor

    What version of Jinja2 does your upgrade end up installing? I can't replicate this bug here. My system (on a blank docs project started via sphinx-quickstart) is:

    • macOS 12.3
    • Python 3.10.3
    • Sphinx 4.4.0
    • Jinja2 3.1.0

    It's possible that this import issue has already been addressed by a version of Sphinx between your 3.5.4 and 4.4.0?

    I can confirm that, via use of iPython, the import error with Jinja2 3.1.0 does appear:

    In [2]: from jinja2 import Environment, environmentfilter
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    Input In [2], in <cell line: 1>()
    ----> 1 from jinja2 import Environment, environmentfilter
    
    ImportError: cannot import name 'environmentfilter' from 'jinja2' (/Users/vhaag/.pyenv/versions/3.10.3/lib/python3.10/site-packages/jinja2/__init__.py)
    
  2. mdylanbell commented on Mar 24, 2022

    @mdylanbell

    I'm also experiencing this bug (and it's breaking our builds). In our case, Jinja2 version 3.0.3 is being installed.

    Sorry, I'm wrong. I think that may be from the most recent working container.

  3. pllim commented on Mar 24, 2022

    @pllim

    Pinning to Jinja2<3.1 fixed it for our project. At first I thought 3.0.3 broke it too until I saw something else undoing my pin in the log; you should check again.

  4. mdylanbell commented on Mar 24, 2022

    @mdylanbell

    @pllim Yes, I was wrong. I updated my original comment. I was mistakenly looking at our last successful container build.

  5. jontwo commented on Mar 24, 2022

    @jontwo
    Author

    Apologies, I thought I was on the latest Sphinx, as this was a new virtual environment. The bug goes away when I install the latest Sphinx so it must have been fixed somewhere along the way. I tried 4.0.0 and 4.0.1 but they require Jinja2<3.0. With Sphinx 4.0.2 the problem goes away, so this ticket can be closed. Many thanks for your help.

  6. Adam-- commented on Mar 24, 2022

    @Adam--

    @jontwo This threw me for a loop too. I was on 2.4.4.
    It looks like the version requirements for Jinja2 were originally >=2.3 and were updated to >=2.3,<3.0 in #9161. That was short lived with support for Jinja2 3.0 being added in #9162.
    To work around this issue until I can use the new version of Sphinx, I just installed an older version of Jinja before installing Sphinx.

  7. pllim commented on Mar 24, 2022

    @pllim

    Re: #10291 (comment) -- Forgot to say our project is pinning to sphinx<4 for a different issue. Should have clarified. Sorry!

  8. added a commit that references this issue on Mar 25, 2022
  9. 38 remaining items

  10. added a commit that references this issue on Apr 6, 2022
  11. added a commit that references this issue on Apr 7, 2022
  12. added a commit that references this issue on Apr 8, 2022
  13. added a commit that references this issue on Apr 12, 2022
  14. added 2 commits that reference this issue on Apr 22, 2022
  15. added a commit that references this issue on Apr 24, 2022
  16. locked as resolved and limited conversation to collaborators on Apr 26, 2022
  17. added a commit that references this issue on Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions