Home > front end >  VSCode Autocomplete And Suggestion (IntelliSense) Doesn't Work For Tensorflow And Keras Librari
VSCode Autocomplete And Suggestion (IntelliSense) Doesn't Work For Tensorflow And Keras Librari

Time:08-30

The VSCode autocomplete option doesn't work for tensorflow and keras libraries; However i've installed python and pylance extension on it; is there any solution to make it work or not, without install new extension or something like as AI autocomplete; Kite and tabinine?

For instance, here i'm trying to use layers or preprocessing from keras API but it doesn't show anything at all

Load Keras Preprocessing Load Keras Layers

Also notice here the tensorflow version and python version

enter image description here

CodePudding user response:

A potentially useful fix:

try adding this to the bottom of your tensorflow/__init__.py

# 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
  • Find the location of the tensorflow package and open the __init__.py file in the tensorflow folder

    enter image description here

  • Add the above codes at the bottom of the file

    enter image description here

  • It should be noted that it will be useful to import in the following way

    import tensorflow as tf
    
    tf.keras
    

    enter image description here

    enter image description here

  • Importing in the previous way still can't get intellisense

    enter image description here

    enter image description here

  • Related