我刚在新笔记本电脑上安装了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} ...但是tensorflow从命令提示符加载没有(很多)问题
令人困惑的是,当我通过anaconda提示加载tensorflow时 - >激活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:
任何帮助将非常感激。谢谢,CN
对于你的{1}问题,因为你在{2}中激活了Tensorflow,我猜你的Spyder安装在不同的环境中。也许您可以尝试从Preference-> Console-> Advanced settings更改Spyder的python解释器。对于{4},你安装了Nvidia Cuda工具吗?希望这会有所帮助。
最好,罗宾
在tensorflow环境中安装spyder。源激活tensorflow(linux)或激活tensorflow(你创建的环境,如果有的话)(windows),然后,conda install spyder。首先激活tensorflow环境,然后每次启动spyder。祝你好运,沃克