Skip to content

Fix: Migrate pkg_resources to import lib.resources for Python 3.9+ compatibility - #537

Open
RahmaniSajjad wants to merge 1 commit into
facebookresearch:mainfrom
RahmaniSajjad:main
Open

Fix: Migrate pkg_resources to import lib.resources for Python 3.9+ compatibility#537
RahmaniSajjad wants to merge 1 commit into
facebookresearch:mainfrom
RahmaniSajjad:main

Conversation

@RahmaniSajjad

Copy link
Copy Markdown

Summary

This PR replaces the deprecated pkg_resources.resource_filename() with importlib.resources.files() in sam3/model_builder.py. This migration is necessary to support setuptools >= 82.0.0, which removed the pkg_resources API.

Changes

  • Removed import pkg_resources.
  • Integrated from importlib.resources import files.
  • Updated the following functions to use importlib for asset path resolution:
    • build_sam3_image_model
    • build_sam3_video_model
    • build_sam3_multiplex_video_predictor
  • Cast Traversable objects to str to ensure backward compatibility with SimpleTokenizer.

Context

The previous implementation relied on an API that is no longer available in the latest setuptools releases, causing installation and runtime failures in modern Python environments. Using importlib.resources (available since Python 3.9) provides a stable, built-in solution and removes the runtime dependency on setuptools for asset resolution.

Related Issues

Fixes #462

Migrate asset resolution in sam3/model_builder.py to use importlib.resources. This fixes compatibility issues with setuptools >= 82.0.0, where pkg_resources.resource_filename() was removed. No functional changes introduced.
@meta-cla

meta-cla Bot commented Apr 27, 2026

Copy link
Copy Markdown

Hi @RahmaniSajjad!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Apr 27, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module pkg_resources not found. Problems running examples.

1 participant