Skip to content

Remove distutils from the TensorFlow version check - #2045

Open
Nas01010101 wants to merge 1 commit into
tensorflow:mainfrom
Nas01010101:fix-distutils-import
Open

Nas01010101 wants to merge 1 commit into
tensorflow:mainfrom
Nas01010101:fix-distutils-import

Conversation

@Nas01010101

Copy link
Copy Markdown

Fixes #2044.

_validate_tf_environment imports distutils.version on every call. Python 3.12 removed distutils, and tensorflow/tensorflow#116901 stopped installing setuptools, which provided a shim. With tf-nightly or tensorflow==2.22.0rc1, import tensorflow_probability now fails with ModuleNotFoundError.

distutils was used only for version strings that packaging rejects, and that path raised TypeError because it compared a LooseVersion with a Version.

Changes:

  • __init__.py: for a version that packaging rejects, parse its leading release number (2.19.0 from 2.19.0-custom-build) with packaging. No distutils import.
  • BUILD: removed the distutils dep and added the init_test target.
  • init_test.py: checks that _validate_tf_environment runs with distutils blocked in sys.modules, accepts 2.19.0-custom-build, and rejects 2.17.0-custom-build.

Testing (Python 3.12, tf-nightly 2.23.0.dev20261120, no setuptools):

  • bazel test //tensorflow_probability/python:init_test (Bazel 6.4.0): passes with this change and fails on main with ModuleNotFoundError. With setuptools installed, main fails 2 of the 3 tests with TypeError.
  • tfp.distributions.Normal(0., 1.).log_prob(0.) returns -0.9189.
  • pylint --rcfile=testing/pylintrc on both Python files: 10.00/10.

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.

import tensorflow_probability fails on Python 3.12+ without setuptools

1 participant