Tensorflow not being able to be imported, can't pip install?

Viewed 23

I have a ipynb notebook running Python 3.10.7 64-bit on MacOS in Visual Studio. I did:

pip install tensorflow 

which resulted in the following error:

ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

I then used the following code:

pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl

Which appeared to work fine installing tensorflow, but the following code:

from tensorflow.keras.layers.experimental.preprocessing import StringLookup
from tensorflow import keras

Yields this error:

Traceback (most recent call last):

  File ~/Library/Python/3.10/lib/python/site-packages/IPython/core/interactiveshell.py:3378 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In [9], line 1
    from tensorflow.keras.layers.experimental.preprocessing import StringLookup

  File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/__init__.py:24
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import

  File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/__init__.py:49
    from tensorflow.python import pywrap_tensorflow

  File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow.py:58
    from tensorflow.python.pywrap_tensorflow_internal import *

  File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                         ^
SyntaxError: invalid syntax

I attempted to use a different version of Python (3.6 and 3.7), but the error still persists. Any suggestions?

1 Answers

So, I also have faced this problem. you have mentioned that after writing pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl this code you installed TensorFlow easily but then you faced some problem SO NOTE MY STEPS:

  1. delete the tensor flow which you installed earlier
  2. follow the youtube video I am sending to download the wheel file of TensorFlow and then try to execute from tensorflow.Keras.layers.experimental.preprocessing import StringLookup from tensorflow import keras //you will find no error //YOUTUBE LINK : https://www.youtube.com/watch?v=-3am_5jMzJ4
Related