tensorflow: Raspbian 9 (Stretch): Failed to load native TensorFlow runtime


System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No. Simply calling “import tensorflow” already crashes.
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Raspbian GNU/Linux 9 (Stretch)
  • TensorFlow installed from (source or binary): Source
  • TensorFlow version (use command below): TensorFlow 1.6.0
  • Python version: Python 3.5.3
  • Bazel version (if compiling from source): Bazel 0.11.1
  • GCC/Compiler version (if compiling from source): GCC 6.3.0 20170124
  • CUDA/cuDNN version: I didn’t install with CUDA support
  • GPU model and memory: n/a
  • Exact command to reproduce: “import tensorflow” in the Python environment

Describe the problem

I built TensorFlow on Raspbian Linux for the Raspberry Pi 3 Model B. The problem is that when I try to import it in Python, the program instantly crashes, saying: “Failed to load native TensorFlow runtime.” The full traceback is below.

Source code / logs

Only need to call “import tensorflow” on Python3 to reproduce the traceback below:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "/usr/local/lib/python3.5/dist-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.5/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic return _load(spec) ImportError: /usr/local/lib/python3.5/dist-packages/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: _ZN10tensorflow9ConcatCPUINS_8bfloat16EEEvPNS_10DeviceBaseERKSt6vectorISt10unique_ptrINS_6TTypesIT_Li2EiE11ConstMatrixESt14default_deleteIS9_EESaISC_EEPNS8_6MatrixE

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "idex.py", line 1, in import gui File "/home/pi/Desktop/IDEX/scripts/gui.py", line 10, in import fun_util File "signlang/fun_util.py", line 3, in import tensorflow as tf File "/usr/local/lib/python3.5/dist-packages/tensorflow/init.py", line 24, in from tensorflow.python import * # pylint: disable=redefined-builtin File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/init.py", line 49, in from tensorflow.python import pywrap_tensorflow File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "/usr/local/lib/python3.5/dist-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.5/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic return _load(spec) ImportError: /usr/local/lib/python3.5/dist-packages/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: _ZN10tensorflow9ConcatCPUINS_8bfloat16EEEvPNS_10DeviceBaseERKSt6vectorISt10unique_ptrINS_6TTypesIT_Li2EiE11ConstMatrixESt14default_deleteIS9_EESaISC_EEPNS8_6MatrixE

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Hello, I’ve been fiddling around this for a while, there’s actually a clean method without commenting code lines or any ad-hoc solutions, for native building on ARM (I used Orange Pi PC Plus, ARMBIAN 5.38 stable Ubuntu 16.04.4 LTS 4.14.18-sunxi), build bazel version 0.11.1, then I checked out to the revision with latest successful nightly build, luckily it’s version 1.7.0, then you should pass one of the following macros while building (ARM_NON_MOBILE or RASPBERRY_PI), the building command becomes as follows: git checkout -f d82b2f71b60d5fff48884c20c7b85e517330e91f bazel build -c opt --copt=-DRASPBERRY_PI --copt=-mfpu=neon-vfpv4 --copt=-std=gnu11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-O3 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --local_resources 400,2.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package 2>&1 | tee ~/tf_nativebuild.log I found the hint about the macros in this file tensorflow/core/platform/platform.h

// Require an outside macro to tell us if we’re building for Raspberry Pi or // another ARM device that’s not a mobile platform.

Another very convenient alternative is to use the cross-building script that tensorflow maintainers use for nightly ci builds, it’s easier and also much faster, it creates a docker container, installs all required dependencies inside it, then cross-builds tensorflow for arm, you also need to checkout to the stable revision git checkout -f d82b2f71b60d5fff48884c20c7b85e517330e91f tensorflow/tools/ci_build/ci_build.sh PI tensorflow/tools/ci_build/pi/build_raspberry_pi.sh 2>&1 | tee ~/tf_crossbuild.log

Ok it now compiles fine and I can run tensorflow now. Thank you! To clarify, what I did was comment out this line