Skip to content

fix: replace pkg_resources with importlib.metadata for setuptools 82+#286

Open
junagent wants to merge 2 commits intovpython:masterfrom
junagent:fix/replace-pkg-resources-with-importlib
Open

fix: replace pkg_resources with importlib.metadata for setuptools 82+#286
junagent wants to merge 2 commits intovpython:masterfrom
junagent:fix/replace-pkg-resources-with-importlib

Conversation

@junagent
Copy link

Summary

pkg_resources was removed from setuptools 82.0.0 (PEP 740, Feb 2026). This breaks vpython when installed with the latest setuptools.

Fix

Replace pkg_resources usage with the stdlib importlib.metadata module:

  • get_distribution(name).version -> version(name)
  • DistributionNotFound -> PackageNotFoundError

Testing

pip install setuptools>=82
pip install vpython # should work without pkg_resources error
python -c "import vpython; print(vpython.version)"

Fixes #285

Fixes #285

@mwcraig mwcraig added the bug Something isn't working label Mar 19, 2026
Copy link
Contributor

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request @junagent -- a couple minor changes to make. Please ping me @mwcraig when you have revised it or I might not notice it...

@@ -1,4 +1,4 @@
from pkg_resources import get_distribution, DistributionNotFound
from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of trying to make version act like get_distribution, how about just:

Suggested change
from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound
from importlib.metadata import version, DistributionNotFound

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes

Suggested change
__version__ = version(__name__)

which fixes the error in CI.

ALSO revise the name of the exception below.

@junagent
Copy link
Author

Thanks for the review! I want to make sure I understand correctly.

The current fix imports:
from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound

Then uses:
try:
version = get_distribution(name).version
except DistributionNotFound:
pass

Is your suggestion to change it to:
from importlib.metadata import version, PackageNotFoundError as DistributionNotFound
...
try:
version = version(name)
except DistributionNotFound:
pass

Or something else? Happy to revise to match your vision exactly.

Address maintainer review feedback: use version() directly
instead of aliasing to get_distribution(), and update
exception name to PackageNotFoundError.

Fixes vpython#286
@junagent
Copy link
Author

Thanks for the review! I've pushed a new commit addressing your feedback:

  • Removed aliases: from importlib.metadata import version, PackageNotFoundError
  • Changed to direct call: __version__ = version(__name__)
  • Updated cleanup: del version, PackageNotFoundError

The simpler approach is cleaner. Let me know if anything else needs adjustment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setuptools>=82.0 dropped pkg_resources

2 participants