【问题标题】:Error when importing tensorflow in Spyder在 Spyder 中导入 tensorflow 时出错
【发布时间】:2018-01-22 20:43:43
【问题描述】:

我刚刚在新笔记本电脑上安装了 tensorflow。

(Anaconda 4.3.24,Python 3.6.1,TensorFlow:1.2.1,GPU:NVIDIA 1060 6GB)

目前有四个问题。

{1} Spyder 中出现“无法加载本机 TensorFlow 运行时”错误

File "D:/Programs/Codes-Python/OpenCVtest.py", line 13, in <module>
    import tensorflow as tf

  File "D:\Programs\Anaconda\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *

  File "D:\Programs\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow

  File "D:\Programs\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "D:\Programs\Anaconda\lib\site-
packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in 
swig_import_helper
    return importlib.import_module(mname)
  File "D:\Programs\Anaconda\lib\importlib\__init__.py", line 126, in 
import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
  File "D:\Programs\Anaconda\lib\site-
packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\Programs\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
  File "D:\Programs\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
  File "D:\Programs\Anaconda\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

{2} ...但是从命令提示符加载张量流没有(很多)问题

令人困惑的是,当我通过 anaconda prompt 加载 tensorflow -> activate tensorflow -> python -> import tensorflow: 然后导入 tensorflow 时没有错误。

怎么会?如果仅为特定环境安装 tensorflow 库,则 Spyder 中的错误消息应为“No Module Named TensorFlow”....

{3}运行示例时的一些差异

现在当我在 anaconda 提示符下运行测试代码时:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()

我收到以下“错误”?

2017-08-14 23:39:37.137745: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.137929: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.139157: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.139677: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.140599: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.141239: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.141915: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-14 23:39:37.142529: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

但我仍然可以运行测试“print(sess.run(hello))”的最后一部分并得到以下结果。

>>> print(sess.run(hello))
b'Hello, TensorFlow!'

Hello 前面的“b”不应该存在,但在我运行代码时始终存在。为什么?

{4}没有已知的设备错误 - GPU 无法识别? 最后,当我检查正在使用的设备时,tensorflow 似乎无法识别 GPU。为什么?我试过分别卸载、重新安装 tensorflow 和 tensorflow-GPU 无济于事。

>>> sess = tf.Session(config = tf.ConfigProto(log_device_placement=True))
Device mapping: no known devices.
2017-08-14 23:50:42.624086: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\36\tensorflow\core\common_runtime\direct_session.cc:265] Device mapping:

任何帮助将不胜感激。 谢谢, 中文

【问题讨论】:

    标签: python tensorflow anaconda gpu spyder


    【解决方案1】:

    对于您的 {1} 问题,因为您在 {2} 中激活了 Tensorflow,我猜您的 Spyder 安装在不同的环境中。也许您可以尝试从 Preference->Console->Advanced 设置更改 Spyder 的 python 解释器。 对于 {4},您是否安装了 Nvidia Cuda 工具? 希望这会有所帮助。

    最好, 罗宾

    【讨论】:

    • 谢谢,罗宾。 CUDA 8.0(和 cuDNN)已安装,但现在我不确定它是否已“正确”安装。不再提供来自 NVIDIA 的示例程序来验证安装。
    【解决方案2】:

    在 tensorflow 环境中安装 spyder。 源激活 tensorflow(linux) 或激活 tensorflow(你创建的环境,如果有的话)(windows),然后,conda install spyder。 每次都先激活tensorflow环境,再启动spyder。 祝你好运,沃克

    【讨论】:

      猜你喜欢
      • 2015-08-03
      • 1970-01-01
      • 2016-10-28
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      相关资源
      最近更新 更多