您的位置:首页 > 编程语言 > Python开发

windows10下cuda8.0+cudnn6.0+PYthon3.5.3+tensorflow安装

2017-08-22 10:35 681 查看
1.安装tensorflow的版本有CPU和GPU两种,安装支持GPU运算的tensorflow时,需要先安装下面这2个驱动。
1)CUDA   https://developer.nvidia.com/cuda-downloads,此处以cuda8.0为例。
2)cuDNN  https://developer.nvidia.com/cudnn(要注册Nvidia用户,并加入CuDNN开发组,填若干问卷就可以下载了)选择下载版本时要注意和Cuda版本匹配。以cudnn6.0版本为例。解压后覆盖至CUDA的安装目录下,将解压包里面bin、include和lib目录下的文件拷贝到cuda安装目录的相应bin、include和lib文件目录下。
2、TensorFlow支持2种方式安装:



PIP方式,直接去python官网去下载对应的Python Windows安装包就行了,要注意32位和64位版本的选择。
要注意,TensorFlow目前只能用Python 3.5.X版本的。所以不要下载错了版本。
下载链接:https://www.python.org/downloads/release/python-352/
上一篇文章我已经说明了python的安装,在此忽略。
3、安装完Python后,打开CMD界面,输入“python”,可以看到

则python安装成功的。
CPU版本的tensorflow ,输入pip install --upgrade tensorflow
GPU版本的tensorflow,输入pip install --upgrade-gpu
然后等待自动下载。
4、安装完成tensorflow后输入import tensorflow as tf 可以查看是否安装成,如果没有提示任何错误则为成功安装。
可能出现的问题
>>>
import tensorflow as tf
Traceback
(most recent call last):
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line
18,
in swig_import_helper return importlib.import_module(mname)
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\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_removedImportError:

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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line
41,
in <module>
from tensorflow.python.pywrap_tensorflow_internal
import *
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line
21,
in <module> _pywrap_tensorflow_internal
= swig_import_helper()
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line
126,
in import_module return _bootstrap._gcd_import(name[level:],
package, level)
ImportError:
No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback
(most recent call last):
File
"<stdin>", line
1,
in <module>
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\__init__.py", line
24,
in <module>
from tensorflow.python
import *
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\__init__.py", line
51,
in <module>
from tensorflow.python
import pywrap_tensorflow
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line
52,
in <module>
raise ImportError(msg)ImportError:
Traceback (most recent call last):
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line
18,
in swig_import_helper return importlib.import_module(mname)
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\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:
The specified module could
not be found.
During handling of the above exception, another exception occurred:
Traceback
(most recent call last):
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line
41,
in <module>
from tensorflow.python.pywrap_tensorflow_internal
import *
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line
21,
in <module> _pywrap_tensorflow_internal
= swig_import_helper()
File
"C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\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\kimlesj1\AppData\Local\Programs\Python\Python35\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_problemsfor some common reasons and solutions.
Include the entire stack traceabove this error message when asking
for help.
这是由于版本不匹配造成的问题。可以参考https://stackoverflow.com/questions/44287059/tensorflow-importerror-dll-load-failed-and-no-module-named-pywrap-tensorflow
此网站有检测版本不匹配的脚本文件https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c,输入以下代码就可以检测。

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # ==============================================================================
 """A script for testing that TensorFlow is installed correctly on Windows.
 
 The script will attempt to verify your TensorFlow installation, and print
 suggestions for how to fix your installation.
 """
  
 import ctypes
 import imp
 import sys
  
 def main():
 try:
 import tensorflow as tf
 print("TensorFlow successfully installed.")
 if tf.test.is_built_with_cuda():
 print("The installed version of TensorFlow includes GPU support.")
 else:
 print("The installed version of TensorFlow does not include GPU support.")
 sys.exit(0)
 except ImportError:
 print("ERROR: Failed to import the TensorFlow module.")
  
 candidate_explanation = False
  
 python_version = sys.version_info.major, sys.version_info.minor
 print("\n- Python version is
%d.%d."
% python_version)
 if not (python_version
== (3, 5)
or python_version == (3,
6)):
 candidate_explanation = True
 print("- The official distribution of TensorFlow for Windows requires
"
 "Python version 3.5 or 3.6.")
  
 try:
 _, pathname, _ = imp.find_module("tensorflow")
 print("\n- TensorFlow is installed at:
%s"
% pathname)
 except ImportError:
 candidate_explanation = False
 print("""
 - No module named TensorFlow is installed in this Python environment. You may
 install it using the command `pip install tensorflow`.""")
  
 try:
 msvcp140 = ctypes.WinDLL("msvcp140.dll")
 except OSError:
 candidate_explanation = True
 print("""
 - Could not load 'msvcp140.dll'. TensorFlow requires that this DLL be
 installed in a directory that is named in your %PATH% environment
 variable. You may install this DLL by downloading Microsoft Visual
 C++ 2015 Redistributable Update 3 from this URL:
 https://www.microsoft.com/en-us/download/details.aspx?id=53587""")
  
 try:
 cudart64_80 = ctypes.WinDLL("cudart64_80.dll")
 except OSError:
 candidate_explanation = True
 print("""
 - Could not load 'cudart64_80.dll'. The GPU version of TensorFlow
 requires that this DLL be installed in a directory that is named in
 your %PATH% environment variable. Download and install CUDA 8.0 from
 this URL: https://developer.nvidia.com/cuda-toolkit""")
  
 try:
 nvcuda = ctypes.WinDLL("nvcuda.dll")
 except OSError:
 candidate_explanation = True
 print("""
 - Could not load 'nvcuda.dll'. The GPU version of TensorFlow requires that
 this DLL be installed in a directory that is named in your %PATH%
 environment variable. Typically it is installed in 'C:\Windows\System32'.
 If it is not present, ensure that you have a CUDA-capable GPU with the
 correct driver installed.""")
  
 cudnn5_found = False
 try:
 cudnn5 = ctypes.WinDLL("cudnn64_5.dll")
 cudnn5_found = True
 except OSError:
 candidate_explanation = True
 print("""
 - Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow
 requires that this DLL be installed in a directory that is named in
 your %PATH% environment variable. Note that installing cuDNN is a
 separate step from installing CUDA, and it is often found in a
 different directory from the CUDA DLLs. You may install the
 necessary DLL by downloading cuDNN 5.1 from this URL:
 https://developer.nvidia.com/cudnn""")
  
 cudnn6_found = False
 try:
 cudnn = ctypes.WinDLL("cudnn64_6.dll")
 cudnn6_found = True
 except OSError:
 candidate_explanation = True
  
 if not cudnn5_found
or not cudnn6_found:
 print()
 if not cudnn5_found
and not cudnn6_found:
 print("- Could not find cuDNN.")
 elif not cudnn5_found:
 print("- Could not find cuDNN 5.1.")
 else:
 print("- Could not find cuDNN 6.")
 print("""
 The GPU version of TensorFlow requires that the correct cuDNN DLL be installed
 in a directory that is named in your %PATH% environment variable. Note that
 installing cuDNN is a separate step from installing CUDA, and it is often
 found in a different directory from the CUDA DLLs. The correct version of
 cuDNN depends on your version of TensorFlow:
 
 * TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')
 * TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')
 
 You may install the necessary DLL by downloading cuDNN from this URL:
 https://developer.nvidia.com/cudnn""")
  
 if not candidate_explanation:
 print("""
 - All required DLLs appear to be present. Please open an issue on the
 TensorFlow GitHub page: https://github.com/tensorflow/tensorflow/issues""")
  
 sys.exit(-1)
  
 if __name__
== "__main__":
 main()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: