I had to update Tensorflow to the currently latest version 2.11. when importing i get "AttributeError: module 'tensorflow._api.v2.compat.v2.internal' has no attribute 'register_load_context_function'". I have also completely reinstalled a full anaconda environment and downgraded Python to the version compatible with the latest of Tensorflow and then "pip3 install Tensorflow==2.11". Got the same error. I have no other ideas.

The full error log is the following

import tensorflow as tf

AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_432\3752927832.py in <module>
----> 1 import tensorflow as tf

~\AppData\Roaming\Python\Python310\site-packages\tensorflow\__init__.py in <module>
    467 if hasattr(_current_module, "keras"):
    468   try:
--> 469     _keras._load()
    470   except ImportError:
    471     pass

~\AppData\Roaming\Python\Python310\site-packages\tensorflow\python\util\lazy_loader.py in _load(self)
     39     """Load the module and insert it into the parent's globals."""
     40     # Import the target module and insert it into the parent's namespace
---> 41     module = importlib.import_module(self.__name__)
     42     self._parent_module_globals[self._local_name] = module

~\anaconda3\envs\mltrade2\lib\importlib\__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)

~\anaconda3\envs\mltrade2\lib\site-packages\keras\__init__.py in <module>
     19 """
     20 from keras import distribute
---> 21 from keras import models
     22 from keras.engine.input_layer import Input
     23 from keras.engine.sequential import Sequential

~\anaconda3\envs\mltrade2\lib\site-packages\keras\models\__init__.py in <module>
---> 18 from keras.engine.functional import Functional
     19 from keras.engine.sequential import Sequential
     20 from keras.engine.training import Model

~\anaconda3\envs\mltrade2\lib\site-packages\keras\engine\functional.py in <module>
     32 from keras.engine import input_spec
     33 from keras.engine import node as node_module
---> 34 from keras.engine import training as training_lib
     35 from keras.engine import training_utils
     36 from keras.saving.legacy import serialization

~\anaconda3\envs\mltrade2\lib\site-packages\keras\engine\training.py in <module>
     43 from keras.saving.experimental import saving_lib
     44 from keras.saving.legacy import hdf5_format
---> 45 from keras.saving.legacy import save
     46 from keras.saving.legacy import saving_utils
     47 from keras.saving.legacy import serialization

~\anaconda3\envs\mltrade2\lib\site-packages\keras\saving\legacy\save.py in <module>
     22 from keras.saving.legacy import serialization
     23 from keras.saving.legacy.saved_model import load as saved_model_load
---> 24 from keras.saving.legacy.saved_model import load_context
     25 from keras.saving.legacy.saved_model import save as saved_model_save
     26 from keras.utils import traceback_utils

~\anaconda3\envs\mltrade2\lib\site-packages\keras\saving\legacy\saved_model\load_context.py in <module>
---> 68 tf.__internal__.register_load_context_function(in_load_context)

AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'register_load_context_function'

1 Answer 1


According to this source, this error may be happening because you have the Keras package installed in your environment. Try uninstalling it:

pip uninstall keras
pip install tensorflow==2.11
  • $\begingroup$ uninstalled keras, reinstalled tensorflow, last line of tensorflow installation log was "Successfully installed keras-2.11.0". Relunched conda environment and jupyter notebook kernel. Same error. Disperation! $\endgroup$
    – fede72bari
    Feb 21, 2023 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.