AttributeError: module 'tensorflow' has no attribute 'compat'

Viewed 1261

Since my CPU doesn't support AVX instructions and I want to install a newer version of Tensorflow (>= 2.0), I installed a tensorflow wheel for my Python version from https://github.com/fo40225/tensorflow-windows-wheel using pip

However, when trying to import tensorflow, I get the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 45, in <module>
    from . _api.v2 import compat
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 23, in <module>
    from . import v1
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 664, in <module>
    from tensorflow_estimator.python.estimator.api._v1 import estimator
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1 import estimator
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1.estimator import experimental
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
    from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 33, in <module>
    from tensorflow_estimator.python.estimator import estimator
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 53, in <module>
    from tensorflow_estimator.python.estimator import util as estimator_util
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\util.py", line 75, in <module>
    class _DatasetInitializerHook(tf.compat.v1.train.SessionRunHook):
AttributeError: module 'tensorflow' has no attribute 'compat'

I have searched, but not found anybody who encountered the same issue using tensorflow wheel (just trying to install tensorflow via "pip install tensorflow" isn't going to work for me, as I will run into the ImportError: DLL load failed-error).

1 Answers

It seems tensorflow is not installed in your system in the proper way which causes this error.
You need to install tensorflow using any of the below command:

pip install tensorflow   
pip install tensorflow-gpu  # to install tensorflow for gpu support
pip install tensorflow==2.4.0  # to install a specific tensorflow version

For Anaconda environment in jupyter notebook, use below code:

conda install tensorflow
conda install tensorflow-gpu  # to install tensorflow for gpu support

Please follow this link which has step wise instructions to install tensorflow in your system.

Related