You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Reacted by Adam Anderson, Matthew Bell, Noah-Lake-Shore-Cryotronics, Beinan, P. L. Lim, Henry Schreiner, Francis Charette-Migneault, Etienne Landuré, Raffaello Bonghi, Florian Huber and 6 more
Reacted by Gaurav Sheni, Noah-Lake-Shore-Cryotronics, Matthew Bell, Bajrang Panigrahi and Cody Baker
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)
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.
Reacted by Matthew Bell and Etienne Landuré
Reacted by Joshua Beretta, Francis Charette-Migneault, Cody Baker, Yurio Windiatmoko, Martin Folkers, M, BillyGLW and 林玮 (Jade Lin)
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.
@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.
Activity
ViktorHaag commentedon Mar 24, 2022
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: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:
mdylanbell commentedon Mar 24, 2022
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.
pllim commentedon Mar 24, 2022
Pinning to
Jinja2<3.1fixed 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.mdylanbell commentedon Mar 24, 2022
@pllim Yes, I was wrong. I updated my original comment. I was mistakenly looking at our last successful container build.
jontwo commentedon Mar 24, 2022
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.
Adam-- commentedon Mar 24, 2022
@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.
pllim commentedon Mar 24, 2022
Re: #10291 (comment) -- Forgot to say our project is pinning to
sphinx<4for a different issue. Should have clarified. Sorry!unpin sphinx <4, pin jinja<3.1 (relates to sphinx-doc/sphinx#10291)
MAINT: Pin jinja2<3.1 to avoid breaking sphinx
MAINT: Pin jinja2<3.1 to avoid breaking sphinx
Upgrade Sphinx to 4.4.0
Adjust dependencies to use Sphinx<4
Adjust dependencies to use Sphinx<4
Adjust dependencies to use Sphinx<4 and Jinja2<3.1
38 remaining items
Pinning jinja2<3.1
docs: Upgraded esp-docs version to 0.2.4
fix Jinja2 version to solve sphinx error: sphinx-doc/sphinx#10291
yet another workaround for sphinx (#707)
doc: pin Jinja2 version
Bump Sphinx to 4.0.2
Bump Sphinx to 4.0.2 (#70)
🧪 CI: Skip testing for Sphinx v3
Fix the doc-generating CI by pinning an older Jinja2 version
Fix docs build.
Fix docs build.
unpin sphinx
doc: dpgen run machine parameters (#710)
fix sphinx-doc/sphinx#10291