Reputation: 429
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
Upvotes: 29
Views: 63493
Reputation: 141
Tried everything above but the only thing that worked is downgrading Tensorflow to 2.9.1 using python -m pip install tensorflow-gpu==2.9.1
. I selected this version because on the PyPi page there wasn't any version after this for a while (4 months!) so I assumed that this version is stable and it worked! I was getting this error with Tensorflow 2.10.0 on a mamba environment.
Upvotes: 0
Reputation: 1
I too faced this issue when trying to import any tensorflow package. More specifically I was trying to load a model so I was using the load_model attribute in tensorflow.keras.
The above issue maybe because we are using a higher/unstable version of Tensorflow. I resolved this by installing a lower, stable version of Tensorflow and Keras and then everything seems to work as an exe file as well. -
Just run this in your windows terminal:
pip install tensorflow==2.12.0
Upvotes: 0
Reputation: 11
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"
Upvotes: 0
Reputation: 1004
Running pip3 install numpy --upgrade
solved this issue for me.
Upvotes: 58
Reputation: 910
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
Upvotes: 3