Unable to import 'tensorflow.keras' PylintE0401:import-error in visual studio code

I am trying to play around with the tensorflow library in visual studio code.

I have installed tensorflow using pip which also installs keras, version 2.15 both.

In visual studio code, for some reason pylint complains about the following, although the code runs without any issues

Anyone experinced this and any suggestions ?

Thanks !

See item C.4 in the FAQ.


thanks @TMosh, I have installed tensorflow and the code does work when I execute the code.

Why does visual studio code complain though that the package is not available. Because of this issue the intellisense does not work as well which makes it cumbersome to explore the tensorflow objects and methods.


Sorry, I do not know.
Supporting visual studio is not part of my responsiblity.

Just an update. I am able to fix this issue by using the following code. Seems like keras is not a package under tensorflow which is why vsc complains, though still not sure as to how the code execution works and finds the correct keras submodules. I saw that there is some code to lazy-load keras v2/3 in the init.py module of tensorflow, but do not understand how this works and if this is what makes the code execution work.