Tensorflow_probability not working for me

I can’t import tensorflow_probability on a Windows 10 , Python 10 system.

import tensorflow as tf
import tensorflow_probability as tfp
print(tf.version)

Error :

Traceback (most recent call last):
File “D:\gCloud\GoogleDrive\colabai\stat\tfp\dist1\tfp1.py”, line 3, in
import tensorflow_probability as tfp
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_probability_init_.py”, line 22, in
from tensorflow_probability.python import * # pylint: disable=wildcard-import
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_probability\python_init_.py”, line 152, in
dir(globals()[pkg_name]) # Forces loading the package from its lazy loader.
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_probability\python\internal\lazy_loader.py”, line 57, in dir
module = self.load()
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_probability\python\internal\lazy_loader.py”, line 37, in load
self.on_first_access()
File "C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_probability\python_init
.py", line 79, in validate_tf_environment
import tf_keras # pylint: disable=unused-import
File "C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras_init
.py", line 3, in
from tf_keras import internal
File "C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras_internal
_init
.py", line 3, in
from tf_keras.internal import backend
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras_internal_\backend_init_.py”, line 3, in
from tf_keras.src.backend import initialize_variables as initialize_variables
File "C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src_init
.py", line 21, in
from tf_keras.src import applications
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\applications_init_.py”, line 18, in
from tf_keras.src.applications.convnext import ConvNeXtBase
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\applications\convnext.py”, line 33, in
from tf_keras.src.engine import sequential
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\engine\sequential.py”, line 24, in
from tf_keras.src.engine import functional
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\engine\functional.py”, line 33, in
from tf_keras.src.engine import training as training_lib
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\engine\training.py”, line 48, in
from tf_keras.src.saving import saving_api
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\saving\saving_api.py”, line 25, in
from tf_keras.src.saving.legacy import save as legacy_sm_saving_lib
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\saving\legacy\save.py”, line 27, in
from tf_keras.src.saving.legacy.saved_model import load_context
File “C:\Users\Gilles\AppData\Local\Programs\Python\Python310\lib\site-packages\tf_keras\src\saving\legacy\saved_model\load_context.py”, line 68, in
tf.internal.register_load_context_function(in_load_context)
AttributeError: module ‘tensorflow._api.v2.compat.v2.internal’ has no attribute ‘register_load_context_function’. Did you mean: ‘register_call_context_function’?

I just uninstalled (including keras) and re-installed all tensorflow libraries :

pip list:
keras 3.5.0
Keras-Preprocessing 1.1.2
tensorboard 2.17.1
tensorboard-data-server 0.7.2
tensorflow 2.17.0
tensorflow-datasets 4.9.6
tensorflow-hub 0.16.1
tensorflow-intel 2.17.0
tensorflow-io-gcs-filesystem 0.31.0
tensorflow-metadata 1.15.0
tensorflow-probability 0.24.0

Hi @Gilles_Jack, I have tried to install tfp in the windows machine and did not face any error. Could you please try to create new environment and install tfp.

Thank You.

I fixed the issue by manually deleting all tensorflow libraries in AppData\Local\Programs\Python\Python310\Lib\site-packages folder and reinstalling everything.