繁体   English   中英

张量流导入错误:_pywrap_tensorflow_internal.so:未定义符号:PyClass_Type

[英]tensorflow import error: _pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

我想做Streaming Accuracy并按照Tensorflow Audio识别官方网页上的说明进行操作 我的环境是 virtualenv 中的 Ubuntu 16.04、Python 3.5、tensorflow 16.0。

在 virtualenv 环境中运行此命令后,

bazel run tensorflow/examples/speech_commands:generate_streaming_test_wav

一些错误信息出来了。 请检查此要点以获取更多详细信息。

简而言之,

第 1~7 行:我想确保导入 tensorflow 没问题

第 9~69 行:错误消息显示 Failed to load the native TensorFlow runtime。

INFO: Running command line: bazel-bin/tensorflow/examples/speech_commands/generate_streaming_test_wav
Traceback (most recent call last):
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/jean_lin/py35_tf16/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/jean_lin/py35_tf16/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/examples/speech_commands/generate_streaming_test_wav.py", line 47, in <module>
    import tensorflow as tf
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *  # pylint: disable=redefined-builtin
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/jean_lin/py35_tf16/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/jean_lin/py35_tf16/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/jean_lin/.cache/bazel/_bazel_jean_lin/7ec2afa2cc3b112c8391a9677667186f/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/examples/speech_commands/generate_streaming_test_wav.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type


Failed to load the native TensorFlow runtime.

第 72~93 行:我不知道为什么它无法加载原生 tensorflow。 我尝试再次导入 tensorflow。 并发现我无法正确导入 tensorflow。

Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/home/jean_lin/kws/tensorflow/tensorflow/python/platform/self_check.py", line 25, in <module>
    from tensorflow.python.platform import build_info
ImportError: cannot import name 'build_info'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jean_lin/kws/tensorflow/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *  # pylint: disable=redefined-builtin
  File "/home/jean_lin/kws/tensorflow/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/jean_lin/kws/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 25, in <module>
    from tensorflow.python.platform import self_check
  File "/home/jean_lin/kws/tensorflow/tensorflow/python/platform/self_check.py", line 27, in <module>
    raise ImportError("Could not import tensorflow. Do not import tensorflow "
ImportError: Could not import tensorflow. Do not import tensorflow from its source directory; change directoryto outside the TensorFlow source tree, and relaunch your Python interpreter from there.

任何建议将不胜感激。 谢谢。

关于最后一个错误:ImportError:无法导入张量流。 不要从其源目录导入 tensorflow;

这意味着您不能在源代码路径的根目录中“导入 tensorflow”(例如:/tensorflow-2.2.0)。 您只需找到另一条路径,然后“导入 tensorflow”。

关于第一个错误,我想我遇到了一个类似的错误,我的解决方案是

  1. pip卸载张量流
  2. 重建张量流
  3. 重新安装 tensorflow。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM