导入张量流时未定义的符号:_PyThreadState_Current

时间:2019-05-06 09:25:14

标签: python-3.x tensorflow raspberry-pi3

我正在使用raspberry pi3。正在运行Raspbian9。在https://neoctobers.readthedocs.io/en/latest/rpi/install_python3.html之后安装了Python版本3.7.2。使用update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1

使python3指向python3.7.2

这是我得到的错误:

pi@raspberrypi:~ $ python3
Python 3.7.2 (default, May  5 2019, 18:41:29) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/opt/python-3.7.2/lib/python3.7/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/local/opt/python-3.7.2/lib/python3.7/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/local/opt/python-3.7.2/lib/python3.7/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: _PyThreadState_Current

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/opt/python-3.7.2/lib/python3.7/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/local/opt/python-3.7.2/lib/python3.7/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/local/opt/python-3.7.2/lib/python3.7/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /usr/local/opt/python-3.7.2/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: _PyThreadState_Current

谢谢。

1 个答案:

答案 0 :(得分:0)

Tensorflow wheel和Python 3.7(https://github.com/bennuttall/piwheels/issues/146)的问题已获批准。看来没有办法轻轻地解决它。

我已成功使用Python 3.5.3在RPi3上成功安装了tensorflow 1.13.0:

$ python3 --version
Python 3.5.3

$ pip3 freeze | grep tensorflow
tensorflow==1.13.1
tensorflow-estimator==1.13.0

此设置有效,但是tensorflow引发与运行时版本兼容性有关的警告:

$ python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
  return f(*args, **kwds)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
tf.Tensor(624.73706, shape=(), dtype=float32)

您可以尝试使用那些警告(禁止它们)或考虑从此仓库https://github.com/lhelontra/tensorflow-on-arm/releases中为RPi构建替代的tensorflow(看起来仅适用于Python 3.5和2.7):

$ pip3 install https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.13.1/tensorflow-1.13.1-cp35-none-linux_armv7l.whl

在我的情况下,它可以正常运行而不会发出任何警告:

$ python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
tf.Tensor(448.25854, shape=(), dtype=float32)