Python Windows 10 Tensorflow(Anaconda)GPU不工作

Python Windows 10 Tensorflow(Anaconda)GPU不工作,python,python-3.x,tensorflow,windows-10,anaconda,Python,Python 3.x,Tensorflow,Windows 10,Anaconda,在我的机器上安装tensorflow gpu时遇到很多问题。Tensorflow 1.3工作得非常完美,但当我尝试使用Tensorflow gpu时,最终出现以下错误: ImportError: Traceback (most recent call last): File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py"

在我的机器上安装tensorflow gpu时遇到很多问题。Tensorflow 1.3工作得非常完美,但当我尝试使用Tensorflow gpu时,最终出现以下错误:

ImportError: Traceback (most recent call last):
  File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 985, in _gcd_import
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 957, 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 938, in create_module
  File "<frozen importlib._bootstrap>", line 222, 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 "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\Freddie\Anaconda3\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

这里似乎什么都没用。

我找到了正确的答案。问题是我正在运行代码,但anaconda下的PATH变量不包括CUDA8
bin
目录

为了解决这个问题,我创建了一个名为CUDA_8_HOME的环境变量,设置为
bin
dir的路径,然后将其添加到脚本的顶部:

import os
os.environ["PATH"] = os.environ["PATH"] + os.environ["CUDA_8_HOME"]

from keras import backend as K
import tensorflow as tf
<... Script Continues ...>
导入操作系统
os.environ[“PATH”]=os.environ[“PATH”]+os.environ[“CUDA_8_HOME”]
从keras导入后端为K
导入tensorflow作为tf

事实证明,使用windows对话框(在“开始”菜单中搜索环境变量)将CUDA home(
bin
目录)添加到路径也可以起作用。

这不是一个简单的解决方案,您可能已经看到了这一点,但相关的Github问题是@PeteWarden我找到了我的问题的解决方案,详细说明如下:
import os
os.environ["PATH"] = os.environ["PATH"] + os.environ["CUDA_8_HOME"]

from keras import backend as K
import tensorflow as tf
<... Script Continues ...>