Skip to content

Replace deprecated distutils and pkg_resources with modern alternatives#1160

Open
dhruvildarji wants to merge 1 commit into
carla-simulator:masterfrom
dhruvildarji:fix/replace-deprecated-distutils-pkg-resources
Open

Replace deprecated distutils and pkg_resources with modern alternatives#1160
dhruvildarji wants to merge 1 commit into
carla-simulator:masterfrom
dhruvildarji:fix/replace-deprecated-distutils-pkg-resources

Conversation

@dhruvildarji

@dhruvildarji dhruvildarji commented Feb 24, 2026

Copy link
Copy Markdown

Summary

  • Replace distutils.version.LooseVersion fallback with direct packaging.version.Version import (distutils was removed in Python 3.12)
  • Replace pkg_resources fallback with direct importlib.metadata.metadata import (available since Python 3.8, which is already the minimum required by numpy 1.24.4)
  • Add packaging as an explicit dependency in requirements.txt

Motivation

The distutils module was deprecated in Python 3.10 and removed entirely in Python 3.12 (PEP 632). Similarly, pkg_resources from setuptools is deprecated in favor of importlib.metadata (available since Python 3.8).

Since the project already requires Python 3.8+ (numpy 1.24.4 requires it), both packaging.version.Version and importlib.metadata are guaranteed to be available, making the try/except fallbacks unnecessary.

This partially addresses #1128 by removing deprecated imports that cause warnings and failures on newer Python versions.

Changes

  • scenario_runner.py: Replaced try/except import blocks with direct imports
  • requirements.txt: Added packaging as an explicit dependency (was previously only used if available)

Test plan

  • Verify python scenario_runner.py --help runs without import errors on Python 3.8+
  • Verify pip install -r requirements.txt succeeds and includes packaging

This change is Reviewable

- Replace `distutils.version.LooseVersion` fallback with direct
  `packaging.version.Version` import (distutils was removed in Python 3.12)
- Replace `pkg_resources` fallback with direct `importlib.metadata` import
  (available since Python 3.8, which is already the minimum for numpy 1.24)
- Add `packaging` as an explicit dependency in requirements.txt

Fixes carla-simulator#1128

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant