'Pycharm highlights code import tensorflow.compat.v1

I've got code that does import tensorflow.compat.v1. Import is going with no errors but PyCharm highlighted this code and says No module named compat. My tensorflow version is 2.4.1
enter image description here

Why does PyCharm say that there's no module compat but the program executes correctly?
Why doesn't the program fails on this line while executing?



Solution 1:[1]

I guess rewriting it as import tensorflow._api.v2.compat.v1 as tf would work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lbska tempo