librenms icon indicating copy to clipboard operation
librenms copied to clipboard

pkg_resources is deprecated and removed in Python 3.12

Open dot-mike opened this issue 8 months ago • 3 comments

The problem

I was trying to set-up a development environment for LibreNMS. I was using pyenv to install python 3.13 and noticed that after running composer install command I was getting error from post install script.

> scripts/dynamic_check_requirements.py || pip3 install --user -r requirements.txt || :
Traceback (most recent call last):
  File "/home/dot-mike/code/librenms/scripts/dynamic_check_requirements.py", line 12, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Turns out that pkg_resources is deprecated https://setuptools.pypa.io/en/latest/pkg_resources.html

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.

setuptools that includes this module was removed as per default in 3.12 https://docs.python.org/3/whatsnew/3.12.html Although the docs do specify python3-setuptools as part of the installation command.

the dynamic_check_requirements.py script should move to use importlib instead.

Output of ./validate.php

.

What was the last working version of LibreNMS?

No response

Anything in the logs that might be useful for us?


dot-mike avatar Mar 21 '25 21:03 dot-mike

Fixes are welcome.

murrant avatar Mar 22 '25 19:03 murrant

any update about this issue ?

anetrjuns avatar Apr 25 '25 13:04 anetrjuns

I'm not sure what the supported versions of python3 are ... but I guess we will get bitten by this at some stage.

I'm also not sure why we do a check to see if modules are satisfied and only if that fails we run the pip install -r requirements.txt .... sort of seems like we could just run it anyway regardless and save a bunch of additional foo?

Anyway will throw an updated script and see how that works for people.

peejaychilds avatar Apr 29 '25 07:04 peejaychilds