miguelgrinberg / microblog

The microblogging application developed in my Flask Mega-Tutorial series. This version maps to the 2024 Edition of the tutorial.
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
MIT License
4.52k stars 1.62k forks source link

Chapter 13: Trying to extract text with pybabel causes AttributeError #330

Closed tsunamistate closed 9 months ago

tsunamistate commented 1 year ago

OS: Windows 11 22H2 Python: v3.11.0 Flask: v2.2.2 Jinja2: 3.1.2 Babel: 2.11.0 Flask-Babel: 2.0.0

After marking needed text for translation and adding babel.cfg, trying to extract the text with pybabel extract -F babel.cfg -k _l -o messages.pot . results in the following error

AttributeError: module 'jinja2.ext' has no attribute 'autoescape'

Looking at Jinja documentation, it looks like both jinja2.ext.autoescape and jinja2.ext.with_ extensions were removed in Jinja 2.9, as they are now built-in: https://jinja.palletsprojects.com/en/3.1.x/extensions/#with-statement https://jinja.palletsprojects.com/en/3.1.x/extensions/#autoescape-extension

In fact, removing extensions=jinja2.ext.autoescape,jinja2.ext.with_ line from babel.cfg fixes text extraction

miguelgrinberg commented 1 year ago

Correct, this broke with a recent update to Jinja. I haven't updated here, but it's on my list of updates to make also on the text of the tutorial.

NicolasTfile commented 10 months ago

I still am unable to fix this issue, 8 already removed the extensions line from babel.cfg but I'm still getting the error "ValueError: Unknown extraction method 'jinja2'" when I run the pybabel command

miguelgrinberg commented 10 months ago

@NicolasTfile this is how the babel.cfg file should be with current versions of pybabel: https://github.com/miguelgrinberg/microblog/blob/2023/babel.cfg

NicolasTfile commented 10 months ago

Thank you, that is also what I did before but I have fixed my issue now. I had to upgrade my setuptools which fixed the issue for me. For others the command to upgrade setuptools is pip install --upgrade setuptools

miguelgrinberg commented 9 months ago

Closing as this does not apply to the new edition of this tutorial.

licorice19 commented 2 months ago

Thank you, that is also what I did before but I have fixed my issue now. I had to upgrade my setuptools which fixed the issue for me. For others the command to upgrade setuptools is pip install --upgrade setuptools

still working

craigz commented 1 month ago

i ran into the identical issue and error: "ValueError: Unknown extraction method 'jinja2'". upgrading setuptools with pip install --upgrade setuptools also resolved the issue for me.