Tenserflow/keras

tensorflow.keras not resolving despite TensorFlow 2.10.0

I’m using TensorFlow 2.10.0 and Keras 2.10.0 inside a conda environment (Python 3.10.16) on Windows, specifically because 2.10.0 is the last version with native GPU support on Windows.

However, I’m running into this issue:

from tensorflow.keras import layers
# -> Import "tensorflow.keras" could not be resolved

Even though:

import tensorflow as tf
print(tf.__version__)  # 2.10.0

import keras
print(keras.__version__)  # 2.10.0

Also, running:

python -c "from tensorflow.keras import layers; print(layers.Dense)"

returns:

<class 'keras.layers.core.dense.Dense'>

…which means it technically works, but my IDE (and sometimes runtime) still flags it as unresolved or broken.

I’ve already tried uninstalling/reinstalling both TensorFlow and Keras, and I’m not using standalone keras anymore — only the tensorflow bundled version.

What could be causing this inconsistency? Is it a conflict between standalone Keras and TF-bundled Keras? Any advice is appreciated

This code:

and this code:

are almost certainly not running in the same Python environment. The former runs in an environment where tensorflow and/or keras is not installed, while the latter runs in an environment where they are.

In each of these environments, run import sys; print(sys.path). I think you will find that they do not match.