-
Notifications
You must be signed in to change notification settings - Fork 74.7k
PyCharm doesn't resolve anything under tensorflow.keras #53144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @sanatmpa1! Could you please look at this issue? |
Can you clarify if you mean that autocomplete is not working in Pycharm, or you're not even able to load the modules/functions in tf.keras? |
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you. |
Sorry I thought I replied to this. You can write code and run it and it works, but you don't have autocomplete nor you can go to declaration of any keras function. It's like writing code in notepad :) |
hi, @markorakita before:
after:
it work for me. |
Thanks for sharing your workaround. Can you try as per the suggestion by @cpuimage and let us know if it helps in resolving the auto completion problem? |
@cpuimage Thank you for finding the cause of the problem in the source code! @sanatmpa1 I've tried the workaround and it works, but I don't think it's the complete fix since some of the keras classes are still not visible. For example tensorflow.keras.layers.CenterCrop and tensorflow.keras.layers.Rescaling layers cannot be resolved, this gets highlighted in red with the message "Cannot find reference 'CenterCrop' in __init__.py": I hope someone in your team could take a deeper look and apply the proper fix for the next tensorflow update? |
@cpuimage Thanks, they can be found in that path but that is the old path, in TF 2.7 they were moved from experimental to tensorflow.keras.layers (see API docs) and those new paths should work in IDE. Maybe the same bug that is in These are just the classes that I noticed at a first glance that cannot be resolved, but there might be more, somebody with domain knowledge should really look into this and devise full and proper fix. |
@markorakita Everything is stirred up, for the time being, only part of it can be solved first, and I hope that someone will solve the problem as soon as possible. |
This solution worked for me. Thanks for sharing it. |
Just copy the folder keras from site-packages/tensorflow/python to site-packages/tensorflow. And the auto completion will start working perfectly |
Thanks! It is a simple and prefect way! |
To everyone that's still couldn't make it work. Try this, I just tweaked the popular solution on this thread: modify the file
To: Note that I used
And then make sure to copy folder After all of that, invalidate and restart your IDE This works on my setup using Conda |
It worked on my anaconda also! . Thanks for all your help code completion and that mini documentation is very important for productivity. |
It worked perfectly on PyCharm IDE with TensorFlow 2.13.0! Finally With a small change, instead of copy folder |
Same issue here with tf 2.16.1 |
So far I haven't seen anyone propose this solution, so I'm passing it on. If PyCharm does not suggest the code to you, but the code itself executes (i.e. if you run the code, e.g. tf.keras.layers.LayerNormalization, which the IDE does not suggest, executes correctly), you can install the package:
which contains "stubs" compatible with the corresponding versions of TensorFlow. If you use TensorFlow 2.16.x, you can install, for example, types-tensorflow==2.16.0.20240606 (see which version of TensorFlow these definitions are for).
PyCharm, after refreshing the indexes, should correctly suggest classes contained in TensorFlow, unfortunately it will not suggest documentation, but it always makes writing code easier. |
The stubs are nice, but documentation is what I need most. I decided to downgrade to 2.12.1 to get documentation working again. Now code is linked correctly and documentation works, but GPU support is broken, because I use Cuda 12.3 which requires a newer tensorflow version. |
this issue still exist in PyCharm 2024.2 with TensorFlow 2.16.1 |
I tried this wih Python 3.9 and tensorflow 2.11, though nothing changed!? |
This worked for me as well.. |
Works but that is a dirty way, and I think it need to be repeated after each update |
Sorry for the very late reply. Both me and haifeng has moved to some new project for sometime. Let me cc @mattdangerw and @hertschuh here. |
@qlzh727 Thank you! |
Same problem in 2.18.0. |
Hi, as of Tensorflow 2.16, the preferred way of using keras is to import keras and use it directly: import keras
inputs = keras.Input(...)
My experience is that code completion for |
I don't like having to resolve to importing directly from keras. Doing |
The use of import os
os.environ["KERAS_BACKEND"] = "jax"
import tensorflow as tf
type(tf.keras.ops.ones(()))
|
Has any solution worked? I'm using tensorflow version 2.17.0. |
System information
Describe the problem
I've upgraded tensorflow from 2.5 to 2.7 and now PyCharm doesn't resolve anything under tensorflow.keras.
Other modules of tensorflow work, it's only keras that's problematic. I believe this has something to do with the change in TF 2.6 where keras has been split into a separate PIP package.
People have also been reporting this problem to JetBrains (PyCharm developers): https://youtrack.jetbrains.com/issue/PY-50318
Provide the exact sequence of commands / steps that you executed before running into the problem
~ conda create --name tensorflow27
~ conda activate tensorflow27
~ conda install python=3.9
~ pip install tensorflow
Any other info / logs
/
The text was updated successfully, but these errors were encountered: