Pkg_resources is deprecated warning

Dear Experts,

I am seeing:

DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

and I have googled this, e.g:

but nothing seems to work for me. Have you seen this before? How did you solve it?

Cheers

The solution is to replace whatever you are pkg_resources for with something else, almost always something in importlib.resources.

Since you didn’t show us what you are actually doing, it is not possible to help you further.

1 Like

Dear @MegaIng

Thank you for your reply, I am using an installed script that seems to be called though:

#!/home/acampove/Packages/micromamba/envs/rk/bin/python3.9
# EASY-INSTALL-DEV-SCRIPT: 'rk-extractor==1.1.6','rxe_plot_pull'
__requires__ = 'rk-extractor==1.1.6'
__import__('pkg_resources').require('rk-extractor==1.1.6')
__file__ = '/home/acampove/Packages/RK/rk_extractor/scripts/jobs/rxe_plot_pull'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

the code itself is in rxe_plot_pull, but I am installing the project with:

pip install -e .

and my setup.py is:

from setuptools import setup, find_packages

import os
import glob

#----------------------------------------------
def is_code(file_path):
    try:
        with open(file_path) as ifile:
            ifile.read()
    except:
        return False

    return True
#----------------------------------------------
def get_scripts(dir_path):
    l_obj = glob.glob(f'{dir_path}/*')
    l_scr = [ obj for obj in l_obj if is_code(obj)]

    return l_scr
#----------------------------------------------
def get_packages():
    l_pkg = find_packages(where='src') + ['']

    return l_pkg
#----------------------------------------------
def get_data_packages(pkg):
    l_pkg= [] 
    if pkg == 'extractor_data':
        l_pkg.append('config/*.toml')
        l_pkg.append('npr_data/*/*.json')
        l_pkg.append('rare_sf/*/*.json')
        l_pkg.append('sb_fits/*/*.json')
        l_pkg.append('sig_wgt/*/yld_*.json')
    else:
        raise
        
    return l_pkg          
#----------------------------------------------
setup(  
        name              = 'rk_extractor',
        version           = '1.1.6',
        description       = 'Used to extract RK from simultaneous fits',
        scripts           = get_scripts('scripts/jobs') + get_scripts('scripts/offline'),
        long_description  = '',
        packages          = get_packages(),
        package_dir       = {'' : 'src'},
        package_data      = {'extractor_data' : get_data_packages('extractor_data')}, 
        install_requires  = open('requirements.txt').read().splitlines()
        )

I am not sure what there is causing problems, the problem arises when just doing:

#!/usr/bin/env python3

import warnings
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)

exit(0)

in rxe_plot_pull. So it cannot be what is inside the script, but the way it was installed.

Cheers.

Seems the problem is an outdated version of either setuptools or pip, try upgrading both to the newest version.

This is the github issue for this: [BUG] unexpected DeprecationWarning of pkg_resources from `script (dev).tmpl` · Issue #3981 · pypa/setuptools · GitHub

1 Like

@MegaIng Thanks for the link, I upgraded to:

(rk) acampove@ubuntu:~/Packages/RK/rk_extractor$ pip show pip
Name: pip
Version: 24.2
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: 
Author-email: The pip developers <distutils-sig@python.org>
License: MIT
Location: /home/acampove/Packages/micromamba/envs/rk/lib/python3.9/site-packages
Requires: 
Required-by: 
(rk) acampove@ubuntu:~/Packages/RK/rk_extractor$ pip show setuptools
Name: setuptools
Version: 72.1.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: 
Author: 
Author-email: Python Packaging Authority <distutils-sig@python.org>
License: 
Location: /home/acampove/Packages/micromamba/envs/rk/lib/python3.9/site-packages
Requires: 
Required-by: flavio, parton, tensorboard, tensorflow, tensorflow-cpu

but I still see the problem. However, following the link in github, I did:

pip install --use-pep517 -e .

for the installation, and it makes the warning go away. However that also makes my script not editable anymore, i.e. the changes to the code do not get propagated unless I install again. So I am not going to use use-pep517. Following the same issue you pointed me to, I see that this:

export PYTHONWARNINGS=ignore

works and I will use it, for now. The long term solution seems to be using pyproject.toml instead of setup.py, but I haven’t tested it and I won’t do it soon, given that I am a little busy for now.

Cheers.