'Vscode keras intellisense(suggestion) not working properly

Intellisense works fine on importing phrase

image1

But when it comes with chaining method, it shows diffrent suggestions

image2

Python & Pylance extensions are installed.



Solution 1:[1]

From this issue on github try adding this to the bottom of your tensorflow/__init__.py (in .venv/Lib/site-packages/tensorflow for me)

# Explicitly import lazy-loaded modules to support autocompletion.
# pylint: disable=g-import-not-at-top
if _typing.TYPE_CHECKING:
  from tensorflow_estimator.python.estimator.api._v2 import estimator as estimator
  from keras.api._v2 import keras
  from keras.api._v2.keras import losses
  from keras.api._v2.keras import metrics
  from keras.api._v2.keras import optimizers
  from keras.api._v2.keras import initializers
# pylint: enable=g-import-not-at-top

The problem is because keras is a special class that enables lazy loading and not a normal module.

Edit: With updates to tf, vscode, or something else I'm not having this issue and don't need to use the above fix anymore. I just have to use keras = tf.keras instead of from tensorflow import keras and I have Intellisense working now.

Solution 2:[2]

did you try clearing the cache on your system?

Solution 3:[3]

Solved. Downgrading tensorflow version from 2.6.0 to 2.5.0 solved the problem.

pip install tensorflow==2.5.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ALEX1A
Solution 3 user8659363