AttributeError: module 'tensorflow._api.v2.compat' has no attribute 'v2'

After running the following command,

pip3 install tensorflow

tensorflow 2.10.0 was installed.
Then following,

python3

import tensorflow as tf

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/tensorflow/__init__.py", line 359, in <module>
    _current_module.compat.v2  # pylint: disable=pointless-statement
AttributeError: module 'tensorflow._api.v2.compat' has no attribute 'v2'

above error arises.

Thanks @amanjha for reporting the problem. Will solve & get back to you asap.

There was some conflict in the package versions, solved it by reinstalling these 2 packages.

pip3 uninstall tensorflow
pip3 uninstall tensorflow-cpu-aws
  • Install tensorflow again
pip3 install tensorflow

Now imported tensorflow successfully

Screenshot from 2022-10-31 18-40-46

1 Like