-
Notifications
You must be signed in to change notification settings - Fork 92
Description
When running selene_sdk on Python 3.12, the code fails with a ModuleNotFoundError because it attempts to import pkg_resources.
Starting with Python 3.12, setuptools (which provides pkg_resources) is no longer pre-installed by default in virtual environments (per PEP 632 and Python 3.12 release notes). Furthermore, pkg_resources is officially deprecated.
Traceback:
Plaintext
Traceback (most recent call last):
File ".../predict.py", line 24, in
from selene_sdk.sequences import Genome
File ".../selene_sdk/init.py", line 8, in
from .evaluate_model import EvaluateModel
File ".../selene_sdk/evaluate_model.py", line 13, in
from .sequences import Genome
File ".../selene_sdk/sequences/init.py", line 8, in
from .genome import Genome
File ".../selene_sdk/sequences/genome.py", line 8, in
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
Suggested Fix:
The modern standard is to replace pkg_resources with the standard library modules importlib.resources or importlib.metadata.
As a temporary workaround for users, installing setuptools manually (pip install setuptools) fixes the crash (pip install setuptools==66.1.1,
https://stackoverflow.com/questions/76043689/pkg-resources-is-deprecated-as-an-api) but a long-term fix is updating selene_sdk/sequences/genome.py (and any other files using it) to use importlib.
Example migration:
Instead of:
Python
from pkg_resources import resource_filename
path = resource_filename('selene_sdk', 'data/file.txt')
Use:
Python
from importlib.resources import files
path = files('selene_sdk').joinpath('data/file.txt')
Environment:
Python Version: 3.12+
Selene Version: 0.6.0 (latest)