Skip to content

tensorflow.keras IDE auto-completion fails #56231

Closed

Description

@Yuri-Su
Click to expand!

Issue Type

Bug

Source

binary

Tensorflow Version

tf 2.8 2.9

Custom Code

Yes

OS Platform and Distribution

win mac

Mobile device

No response

Python version

3.10

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

A bug happened!
tensorflow.keras IDE auto-completion fails.
Using "from tensorflow." does not pop up keras, pycharm will report red but it works.
Also, tf 2.5 is normal.
I see there are other people who have had this problem

Standalone code to reproduce the issue

from tensorflow.keras import layers

Relevant log output

No response

Activity

  1. added
    TF 2.9Issues found in the TF 2.9 release (or RCs)
    on May 24, 2022
  2. tilakrayal commented on May 24, 2022

    @tilakrayal
    Contributor

    @Yuri-Su ,
    Could you provide the error log which you are facing issue. It helps to debug the issue. Thank you!

  3. Dadealos commented on May 24, 2022

    @Dadealos

    So... there's no "error log" for code completion failures. As Yuri-Su mentioned, everyone is having the same issue.

    Steps to reproduce:

    1. from tensorflow.keras import Model

    That's literally it. If you want to rule out other IDEs, configuration issues, etc etc, just go to https://www.tensorflow.org/tutorials/quickstart/advanced

    Run the first cell:
    image

  4. Dadealos commented on May 24, 2022

    @Dadealos

    A side question - does everyone just use Notepad++? This has been a persistent issue with VSCode and Pycharm since at least 2017. I'm baffled that it's not fixed, but I don't understand it well enough to fix it myself.

    I would happily just buy a different IDE if there's one that supports code completion and doesn't break on every new TF release.

  5. Yuri-Su commented on May 25, 2022

    @Yuri-Su
    Author

    A side question - does everyone just use Notepad++? This has been a persistent issue with VSCode and Pycharm since at least 2017. I'm baffled that it's not fixed, but I don't understand it well enough to fix it myself.

    I would happily just buy a different IDE if there's one that supports code completion and doesn't break on every new TF release.

    image
    As far as I know, this problem appeared from 2.6 and lasted until 2.9, if it is not solved, I am willing to use pytorch in the future.

  6. tilakrayal commented on May 26, 2022

    @tilakrayal
    Contributor

    @Yuri-Su ,
    I was able to import and execute the code in tensorflow version 2.8. Could you find the gist of it here. Thanks you!

  7. added and removed
    TF 2.9Issues found in the TF 2.9 release (or RCs)
    on May 26, 2022
  8. 73 remaining items

  9. michelkok commented on Nov 29, 2023

    @michelkok

    Not a real solution at all, but I just want to mention that Keras V3 came out yesterday. If you can already use it, then you have no problem with this anymore.

  10. OlegNovosad commented on Dec 6, 2023

    @OlegNovosad

    This is so crazy.

    PyCharm 2023.2.5 and VSCode 1.84.2 (pylance v2023.11.10) still issue with tensorflow 2.15.0.
    I'm starting learning tensorflow, keras and all of that stuff and not being able to see autocompletion and being forced to memorising optimisers, layers, metrics, params etc. is frustrating 😢

  11. haifeng-jin commented on Dec 10, 2023

    @haifeng-jin
    Contributor

    @weidler @OlegNovosad Are you using import keras or from tensorflow import keras?
    import keras should always work for autocompletion.

  12. OlegNovosad commented on Dec 10, 2023

    @OlegNovosad

    @haifeng-jin I'm using import tensorflow as tf and then tf.keras.<whatever>

  13. weidler commented on Dec 11, 2023

    @weidler

    @haifeng-jin Also using import tensorflow as tf. Will switch to import keras though, since with Keras 3.0 that seems to be the recommended approach anyways.

  14. haifeng-jin commented on Dec 19, 2023

    @haifeng-jin
    Contributor

    @OlegNovosad @weidler , Thanks for the reply! Unfortunately, I don't think we can do much about the tf.keras import path.

    On the Keras side, we have implemented a new mechanism for API exporting, which works for both Keras 2 (since TF 2.13) & 3 for code completion. It creates real directories and files under the import path instead of just adding attributes. So it should work with all code completion tools in IDEs.

    A note for new users:
    Please import keras directly in order to use the code completion feature.

  15. lllllllllaa commented on Dec 30, 2023

    @lllllllllaa

    i made it autocompleting by changing import keras section line 397 in init.py tf 2.15 to:

    # Lazy-load Keras v2/3.
    import typing as _typing
    if _typing.TYPE_CHECKING:
      from keras.api._v2 import keras
    else:
      _tf_uses_legacy_keras = (
              _os.environ.get("TF_USE_LEGACY_KERAS", None) in ("true", "True", "1"))
      setattr(_current_module, "keras", _KerasLazyLoader(globals()))
      _module_dir = _module_util.get_parent_dir_for_name("keras._tf_keras.keras")
      _current_module.__path__ = [_module_dir] + _current_module.__path__
      if _tf_uses_legacy_keras:
        _module_dir = _module_util.get_parent_dir_for_name("tf_keras.api._v2.keras")
      else:
        _module_dir = _module_util.get_parent_dir_for_name("keras.api._v2.keras")
      _current_module.__path__ = [_module_dir] + _current_module.__path__
    

    can someone please tell me if it's going to crash

  16. steveepreston commented on Aug 28, 2024

    @steveepreston

    This issue still exist in PyCharm 2024.2 with TensorFlow 2.16.1

  17. olurocks commented on Sep 19, 2024

    @olurocks

    Issue still persists on vscode .... 7 years down the line and no fix

    interesting

  18. steveepreston commented on Sep 19, 2024

    @steveepreston

    This issue still exist in PyCharm 2024.2.1 with TensorFlow 2.17

    I'm wondering why the issue is closed! please re-open it

  19. yuanxiqd commented on Nov 8, 2024

    @yuanxiqd

    This issue still exist in VScode 1.95.2 with Tensorflow 2.18.

  20. steveepreston commented on Nov 8, 2024

    @steveepreston

    @haifeng-jin @Yuri-Su Please re-open the issue. problem still exists in TensorFlow 2.17 and 2.18

  21. Solitaron commented on Dec 1, 2024

    @Solitaron

    TensorFlow's team really really fail me for many times. Changing installation methods multiple times, annoying warnings after running code, and compatibility issues between "import" and IDE

  22. steveepreston commented on Dec 7, 2024

    @steveepreston

    @Letronxis Sadly worst thing is that long time issues like this are marked as closed and no one trying to open and follow them

  23. Roobahist commented on Apr 14, 2025

    @Roobahist

    Still unresolved. VSCode 1.99.2 Tensorflow 2.18.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions