1

I'm trying to use the LSTM neural network found here on my Raspberry Pi 4 Model B

https://machinelearningmastery.com/text-generation-lstm-recurrent-neural-networks-python-keras/

I have trouble running the program, since I get

Traceback (most recent call last):
  File "/home/malasartes/canigo/model-1/model-1.py", line 6, in <module>
    import tensorflow as tf
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                         ^
SyntaxError: invalid syntax

I have read here https://github.com/tensorflow/tensorflow/issues/20690 that there seems to be a problem with the word async, being a keyword. But when I change the keyword to async1 I get another error


Traceback (most recent call last):
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.9/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.9/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: invalid ELF header

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/malasartes/canigo/model-1/model-1.py", line 6, in <module>
    import tensorflow as tf
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.9/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.9/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: invalid ELF header


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

What seems to be the problem now?

Using:

-Raspberry Pi 4 model B with Raspbian OS 64 bits

-Python 3.9.3

-Tensorflow 1.9.0

1 Answer 1

1
ImportError: /home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/
_pywrap_tensorflow_internal.so: invalid ELF header
                                ^^^^^^^^^^^^^^^^^^

This implies you are using binaries not compiled for the Pi, meaning you installed the wrong tensorflow package.

You can confirm this with file /home/malasartes/.local/lib/python3.9/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so. The response should begin with (after the path):

ELF 64-bit LSB pie executable, ARM aarch64
                               ^^^^^^^^^^^

The important bit is indicated. If that isn't there or it is something else (eg. x86-64), the problem is as just described.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.