Tensorflow在Windows下的安装+各种错误解决


基本都是本人实际过程中出现的情况。

采用的是Anaconda安装方式(Anaconda是python科学计算的集成)

很多人不知道这个东西的意义:

介绍:Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存、切换以及各种第三方包安装问题。Anaconda利用工具/命令conda来进行package和environment的管理,并且已经包含了Python和相关的配套工具。

简单说,其有着强大而方便的包管理与环境管理的功能。

learn more:点击打开链接

先说安装过程:

装Anaconda3(自带python3.6)-->(随手给你的python调一下环境变量)--->把(安装路径)...\Anaconda3\Scripts加入到你的path里--->检查conda

--->创建tensorflow空间,装tensorflow --->进入python检查tensorflow

--->如果tensorflow装的是gpu版本的话,装cuda 和 cudnn。(区别gpu和cpu两个版本:gpu跑起来相当快,但需要你的显卡支持cuda)

CUDA官网: https://developer.nvidia.com/cuda-toolkit  

CUDNN官网:https://developer.nvidia.com/cudnn

注意啊,tensorflow1.4现在只支持CUDA8.0 +cudnn6.0  下载cuda9.0/cudnn5.1都是不能支持的

注意:

  1. * TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')  
  2.   * TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')  

用到的代码总结:

cmd--->

conda --version
conda info --envs
conda search --full-name python
conda create --name tensorflow python=3.6

(y)
activate tensorflow
python --version
(python -V)
pip install -ignore-installed --upgrade tensorflow-gpu
python
import tensorflow as tf

tf.__version__

tf.__path__
deactivate



检查和帮助:

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()  



相关资料:

http://blog.csdn.net/darlingwood2013/article/details/60322258

http://blog.csdn.net/doublepython/article/details/71321450

http://blog.csdn.net/u010099080/article/details/53418159

这三个看下来绝对能装好了

tensorflow中文帮助文档+Linux安装:(极客学院)

http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html


if 你安装可能会出这样的问题:

https://www.cnblogs.com/liaojiafa/p/5100550.html


你可能感兴趣的:(Tensorflow)