tensorflow.keras like imports show warnings in PyCharm, work well on command line

Question:

The Error in PyCharm

I get this error when I import modules from TensorFlow in PyCharm.

Cannot find reference ‘keras’ in ‘init.py’

But when I use the tensorflow.python.keras prefix, the warning is not shown. Also, in the command line, no such warning is shown.

>> from tensorflow.keras import activations
>> # No errors!

How can I fix that warning in PyCharm and freely use tensorflow.keras and not tensorflow.python.keras? I’m using Windows 10, TF version 1.12.0 installed using Anaconda and PyCharm 2018.2.5.

Asked By: Shubham Panchal

||

Answers:

After tensorflow gobbled keras, there were problem with tf.keras imports on IDEs although the code works.This was then raised an as issue (Issue #26502)

It seems that there is no import command for keras module in __init_.py of tensorflow package.
When I added from tensorflow.python import keras to __init__.py manually, everything work well.
Maybe there are some problem for package importing after keras was moved from _api to python.

As of tensorflow 2.0, even from tensorflow.python import keras wouldn’t work: basically there is no way of making PyCharm / IDEA help you with syntax. However, this issue is fixed in IDEA 2019.3+ (currently in EAP, so should be in PyCharm EAP)

PyCharm not fixing this problem because they can’t get it. Fix is:

On advanced system settings in Windows, open Environmental Variables and add PyCharm user variable with value shows the "bin" directory of PyCharm.

Answered By: diegokiller
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.