21

I get an error when I import the TensorFlow. I tried to reinstall it but still, I keep getting this error---> TypeError: Unable to convert function return value to a Python type! The signature was () -> handle.

import tensorflow as tf
from tensorflow.keras.layers import Add, Input, Dense, Dropout
from tensorflow.keras.layers import BatchNormalization, Embedding
from tensorflow.keras.layers import Flatten, Concatenate
from tensorflow.keras import regularizers
from keras.regularizers import l1
from keras.regularizers import l2
from tensorflow.keras import regularizers
from keras.models import Sequential
from keras.wrappers.scikit_learn import KerasClassifier
user17300752
  • 339
  • 1
  • 2
  • 5

3 Answers3

51

Running pip3 install numpy --upgrade solved this issue for me.

Rey Abolofia
  • 914
  • 8
  • 12
1

For me, the first error that came from TensorFlow is

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

which suggests a NumPy version mismatch.

Therefore, downgrading NumPy to 1.21.6 should solve the problem:

pip install numpy==1.21.6
M. Zhang
  • 750
  • 8
  • 18
0

Nothing helped me, except for downgrading tensorflow-metal to v.0.6.0:

"pandas>=2.0.0",
"ipykernel>=6.22.0",
"tensorflow-macos>=2.10.0",
"tensorflow-metal==0.6.0",
"openpyxl>=3.1.2",
"plotly>=5.14.1",
"matplotlib>=3.7.1",
"scikit-learn>=1.2.2",
"keras>=2.10.0",
"keras-self-attention>=0.51.0",
"numpy~=1.24",

requires-python = ">=3.9"

Ed Cher
  • 11
  • 2