Skip to content

RFE: Replace use of pkg_resources with importlib.metadata #861

Closed

Description

@kloczek

See discussions:
astropy/astropy#11091
pypa/pip#7413

[tkloczko@devel-g2v SRPMS]$ rpm -ql python-babel | grep py$ | xargs grep pkg_resources
/usr/lib/python3.8/site-packages/babel/messages/checkers.py:        from pkg_resources import working_set
/usr/lib/python3.8/site-packages/babel/messages/checkers.py:        # if pkg_resources is not available or no usable egg-info was found
/usr/lib/python3.8/site-packages/babel/messages/extract.py:            from pkg_resources import working_set
/usr/lib/python3.8/site-packages/babel/messages/extract.py:            # if pkg_resources is not available or no usable egg-info was found

Activity

  1. kloczek commented on Apr 22, 2022

    @kloczek
    Author

    In this case if babel sphinx extension is used in copy.py in some cases it casues effect described in setuptools ticket pypa/setuptools#3279

  2. self-assigned this
    on Oct 1, 2023
  3. azmeuk commented on Dec 24, 2023

    @azmeuk

    I start to see deprecation warnings in some unit test suites:

    babel/messages/checkers.py:160: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
        from pkg_resources import working_set
    
  4. j123b567 commented on Jul 2, 2024

    @j123b567

    It is really bad because pybabel essentially does not work with python 3.12 with third party extractors.

    [python: **.py]
    [jinja2: templates/**.html]

    ValueError: Unknown extraction method 'jinja2'

    With python 3.11, it works ok.

  5. cclauss commented on Jul 3, 2024

    @cclauss
    Contributor

    Can this be solved on Python >= 3.12 by doing pip install setuptools?

    https://docs.python.org/3/whatsnew/3.12.html

    gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

  6. j123b567 commented on Jul 3, 2024

    @j123b567

    @cclauss thank you. It works, so it is good workaround for now.

    We are working on a patch to introduce fallback to importlib.metadata

  7. jhemmje commented on Nov 8, 2024

    @jhemmje

    I also get the error ValueError: Unknown extraction method 'jinja2'. Installing setuptools via pip install setuptools doesn't solve this problem for me. I have tried it on MacOS 15.1 with Python 3.9 and ArchLinux with Python 3.12.

    Edit: I also tried to install setuptools with brew install python-setuptools (Mac) respectively sudo pacman -S python-setuptools (Linux), but that also doesn't help.

    Edit 2: I have found a workaround. Instead of directly using pybabel, I now use ./venv/bin/pybabel, which is working fine. :)

  8. jlc3p commented on Feb 11, 2026

    @jlc3p

    I was also running into the error ValueError: Unknown extraction method 'jinja2' in an AlmaLinux 9 container within a Python 3.9 environment. Trying all the workarounds mentioned above did not work, but I found that specifying jinja2 as an extractor in the project's pybabel.ini file did the trick, so I'm including the example here just in case it might help someone else:

    [python: **.py]
    
    [jinja2: **.html*]
    
    [extractors]
    jinja2 = jinja2.ext:babel_extract
    
  9. akx commented on Sep 29, 2026

    @akx
    Member

    I think this is resolved by #1102 (released in Babel 2.16.0 in 2024).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions