简体   繁体   中英

VSCode Autocomplete And Suggestion (IntelliSense) Doesn't Work For Tensorflow And Keras Libraries?

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

加载 Keras 预处理 加载 Keras 层

Also notice here the tensorflow version and python version

在此处输入图像描述

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

    在此处输入图像描述

  • Add the above codes at the bottom of the file

    在此处输入图像描述

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

    import tensorflow as tf tf.keras

    在此处输入图像描述

    在此处输入图像描述

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

    在此处输入图像描述

    在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM