facebookresearch / facebookresearch/detectron2

Need to futureproof model_zoo.py against setuptools breaking change announced for 2025-12

Open
#5,494 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

Setuptool's "pkg_resources" is deprecated.
It's been announced that setuptools will release version 81 in 2025-12, with pkg_resources removed. (https://setuptools.pypa.io/en/stable/history.html).

For now, if user's setuptools is 80.9.0, then
```
>>> from detectron2 import model_zoo"
```
produces
```
UserWarning: pkg_resources is deprecated as an API.
See https://setuptools.pypa.io/en/latest/pkg_resources.html.
The pkg_resources package is slated for removal as early as 2025-11-30.
Refrain from using this package or pin to Setuptools<81".
```

Once setuptools 81 is released, users with updated setuptools will get an exception (ModuleNotFoundError) instead of the warning. Right?

FWIW, in the detectron2 repo, there are exactly 3 references to pkg_resources.
```
% egrep -r -n pkg_resources . | cat -n
1 ./setup.cfg:9:known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,pkg_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle,packaging,timm,pandas,fairscale,pytorch3d,pytorch_lightning
2 ./detectron2/model_zoo/model_zoo.py:4:import pkg_resources
3 ./detectron2/model_zoo/model_zoo.py:139: cfg_file = pkg_resources.resource_filename(
```

There are several different ways to address, including (but not limited to)

1. require setuptools < 81 (yuck)
2. or, reimplement pkg_resources.resource_filename using importlib.resources. But that's introduced in Python 3.9, and detectron2 retains compatibility to Python 3.7. So new requirement that if Python < 3.9, need separate package importlib_resources to reimplement.
3. or, reimplement pkg_resources.resource_filename less ambitiously.

## Instructions To Reproduce the 🐛 Bug:
1. Hide your existing pkg_resources, to simulate the future setuptools
```
(cd site-packages && mv pkg_resources pkg_resources.genuine)
```
remember to revert!

3. What exact command you run:
```
>>> from detectron2 import model_zoo
```
5. __Full logs__ or other relevant observations:
```
Traceback (most recent call last):
...
File ".../detectron2/model_zoo/model_zoo.py", line 4, in
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
```

## Expected behavior:

This
```
from detectron2 import model_zoo
```
does not raise an exception.

## Environment:

Provide your environment information using the following command:
```
------------------------------- ----------------------------------------------------------------------------------------
sys.platform darwin
Python 3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)]
numpy 1.26.4
detectron2 failed to import
detectron2._C not built correctly: No module named 'detectron2'
Compiler ($CXX) Apple clang version 14.0.0 (clang-1400.0.29.202)
DETECTRON2_ENV_MODULE
PyTorch 2.2.2 @/Users/john/venvs/3.10+LG.v2.9.0+/lib/python3.10/site-packages/torch
PyTorch debug build False
torch._C._GLIBCXX_USE_CXX11_ABI False
GPU available No: torch.cuda.is_available() == False
Pillow 11.3.0
torchvision 0.17.2 @/Users/john/venvs/3.10+LG.v2.9.0+/lib/python3.10/site-packages/torchvision
fvcore 0.1.5.post20221221
iopath 0.1.9
cv2 4.11.0
------------------------------- ----------------------------------------------------------------------------------------
PyTorch built with:
- GCC 4.2
- C++ Version: 201703
- clang 13.1.6
- Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220801 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v3.3.2 (Git Hash 2dc95a2ad0841e29db8b22fbccaf3e5da7992b01)
- OpenMP 201811
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX2
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CXX_COMPILER=/Applications/Xcode_13.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++, CXX_FLAGS= -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_PYTORCH_METAL_EXPORT -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DUSE_COREML_DELEGATE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wsuggest-override -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-pass-failed -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -fno-math-errno -fno-trapping-math -Werror=format -DUSE_MPS -Wno-unused-private-field -Wno-missing-braces, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=2.2.2, USE_CUDA=OFF, USE_CUDNN=OFF, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF,
```

Contributor guide

Open the contributing guide

Research direction

Start with detectron2/model_zoo/model_zoo.py, especially the pkg_resources import and resource_filename call, and check the related entry in setup.cfg. Reproduce the failure by hiding pkg_resources and running `from detectron2 import model_zoo`; done means that import completes without an exception while preserving Python 3.7 compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.