# Error during tensorflow package import -tensorflow.\_api.v2.compat.v2.\_\_internal\_\_

**URL:** <https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455>\
**Category:** General Discussion\
**Tags:** python, tfhub\
**Created:** [March 5, 2024, 3:53am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455 "2024-03-05T03:53:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcus\_Vinicius\_de\_L](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/marcus_vinicius_de_l/32/10507_2.png) [@Marcus\_Vinicius\_de\_L](https://discuss.ai.google.dev/u/Marcus_Vinicius_de_L)\
**Post date:** [March 5, 2024, 3:53am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/1 "2024-03-05T03:53:10Z")

</div>

Hy, everyone!

I’m trying to use tensorflow and tensorflow\_hub.  
But during the tensorflow package import, I’m already getting the following error:

AttributeError: module ‘tensorflow.\_api.v2.compat.v2. **internal** ’ has no attribute ‘register\_load\_context\_function’. Did you mean: ‘register\_call\_context\_function’?

I’m using the current version of python:  
Python 3.12.2

And I’ve also reinstalled tensorflow packed some times, and followed other instructions I’ve found over discussions but not seems to helping.

Does anyone can help me with any tips, please?

Thanks!

---

<div class="post-metadata">

**Author:** ![lgusm](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lgusm/32/6230_2.png) [@lgusm](https://discuss.ai.google.dev/u/lgusm)\
**Post date:** [March 5, 2024, 10:40am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/3 "2024-03-05T10:40:21Z")

</div>

Hi Marcus, welcome to the TF Forum

do you have a code snippet that can reproduce the issue?

also, TFHub now moved to Kaggle Models. I think it would be better to use that route instead.

---

<div class="post-metadata">

**Author:** ![Ananya](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ananya/32/9221_2.png) [@Ananya](https://discuss.ai.google.dev/u/Ananya)\
**Post date:** [March 5, 2024, 10:47am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/4 "2024-03-05T10:47:57Z")

</div>

Hey  
Even I am facing the same problem. I am using the latest python version and I am trying to load one of my trained h5 model file which I have uploaded

```auto
from flask import Flask, request, render_template
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
app = Flask( __name__ )

# Load the pre-trained BERT model
model = tf.keras.models.load_model(
       ("modelnew.h5"),
       custom_objects={'KerasLayer':hub.KerasLayer}
)

```

---

<div class="post-metadata">

**Author:** ![lgusm](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lgusm/32/6230_2.png) [@lgusm](https://discuss.ai.google.dev/u/lgusm)\
**Post date:** [March 5, 2024, 11:12am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/5 "2024-03-05T11:12:19Z")

</div>

can you remove the tensorflow\_hub dependency and show the error please?  
from your code, you are not using it anywhere

---

<div class="post-metadata">

**Author:** ![Ananya](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ananya/32/9221_2.png) [@Ananya](https://discuss.ai.google.dev/u/Ananya)\
**Post date:** [March 5, 2024, 11:37am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/7 "2024-03-05T11:37:08Z")

</div>

It is being used when I am accessing KerasLayer in custom objects in the second last line

---

<div class="post-metadata">

**Author:** ![lgusm](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lgusm/32/6230_2.png) [@lgusm](https://discuss.ai.google.dev/u/lgusm)\
**Post date:** [March 5, 2024, 1:43pm UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/9 "2024-03-05T13:43:36Z")

</div>

Now I see it! thanks for pointing out!

can you make sure that TF and the tf-keras package both have the same version?  
I’ve seen this error today and that was the main issue (specifically if you are using tf 2.16)

---

<div class="post-metadata">

**Author:** ![Marcus\_Vinicius\_de\_L](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/marcus_vinicius_de_l/32/10507_2.png) [@Marcus\_Vinicius\_de\_L](https://discuss.ai.google.dev/u/Marcus_Vinicius_de_L)\
**Post date:** [March 6, 2024, 12:36am UTC](https://discuss.ai.google.dev/t/error-during-tensorflow-package-import-tensorflow-api-v2-compat-v2-internal/24455/10 "2024-03-06T00:36:34Z")

</div>

You were precise.  
Now the error has passed from this line of code.  
Thank you very much!!!
