Anaconda + Spyder + Windows Tensorflow安装

时间:2017-01-16 11:09:42

标签: python windows tensorflow anaconda spyder

主题描述了问题。我无法安装TF并在Windows上的Anaconda withtin Spyder IDE中使用它。在此脚本中安装TF GPU v0.12.1成功完成:

pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-win_amd64.whl

但是,我仍然会收到此错误:

 Traceback (most recent call last):

  File "<ipython-input-1-a2e3a001c740>", line 1, in <module>
    runfile('D:/ERP/SRC/WorkloadPrediction/PythonScripts/test_pys/test_TF.py', wdir='D:/ERP/SRC/WorkloadPrediction/PythonScripts/test_pys')

  File "D:\Programs\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "D:\Programs\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/ERP/SRC/WorkloadPrediction/PythonScripts/test_pys/test_TF.py", line 8, in <module>
    import tensorflow as tf

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

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

ImportError: Traceback (most recent call last):
  File "D:\Programs\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "D:\Programs\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

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


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

我确保安装了Visual C ++ x64 2015 Redist。还尝试了很多重新安装,重新启动,谷歌解决方案等,但没有任何帮助。

尝试运行此脚本:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))

你可以请一些建议吗?

非常感谢你! Artemiy

2 个答案:

答案 0 :(得分:0)

错误消息很明显,您需要在其目录之外初始化TensorFlow。如果这不是您的问题,请检查您的系统中是否安装了MSVCP140.dll(请参阅Pip Installation on Windows下的注意),并考虑您的Cuda和cuDNN已正确安装且其目录已设置在您的系统上%PATH%

答案 1 :(得分:-1)

使用

更新TensorFlow
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-win_amd64.whl