安装tensorflow的艰难历程

环境:

windows10+anaconda3+python3.5

内容有些乱,见谅。。。。

这是成功安装的流程-_-
https://blog.csdn.net/qq_28543355/article/details/89150588

解决:

首先我装的python3.6是32bit不支持tensorflow---->
换成python3.7后,提示缺少各种文件,于是找到了这个帮助文件---->
(这个时候我还不知道只有3.5支持tensorflow,太惨了。。。一阵子瞎折腾)


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

通过运行这段代码,按照console中的提示,我下载了如下三个文件,
(这个时候我也不知道我的AMD显卡不支持gpu版本安装。。。后期导致了电脑闪屏。。。太惨了)
https://developer.download.nvidia.cn/compute/machine-learning/cudnn/
https://developer.download.nvidia.cn/compute/cuda/
https://download.microsoft.com/download/6/D/F/6DF3FF94-F7F9-4F0B-838C-A328D1A7D0EE/vc_redist.x64.exe
下载完成后,按照官网的提示把三个文件分别复制到安装到c盘的NVIDIA Nsight HUD Launcher 文件夹中。

—>然而dos下import tensorflow还是有问题

C:\Users\Admin>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD6
4)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript
ion)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。

–>好的重装一下

pip install tensorflow --upgrade --force-reinstall

–>hh好了,开心

C:\Users\Admin>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD6
4)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> ^Z

-------->回到pycharm运行那段检查代码:

TensorFlow successfully installed.
The installed version of TensorFlow does not include GPU support.

Process finished with exit code 0

emmmmm,这个网站里面很多报错的例子,打开我的蓝灯灯,容我找找看
https://www.tensorflow.org/install/errors
—>我准备把gpu重新安一下。

pip uninstall tensorflow-gpu


pip install tensorflow-gpu

***检测是否安装成功

windows power shell:输入"python"

----输入"import tensorflow as tf"(没反应才说明正常)

----输入“sess=tf.Session()”

----输入“print(sess.run(tf.constant(123)))”

结果是123,ok,tensorflow-gpu安装完毕

可怕的事情发生了T.T

>>> import tensorflow as tf
Traceback (most recent call last):
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript
ion)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\__init__.py
", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-im
port
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\__in
it__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "E:\comSoft\comp\Python\Python37\lib\site-packages\tensorflow\python\pywr
ap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript
ion)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "E:\comSoft\comp\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

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

似乎CUDA不支持AMD显卡。。。

电脑屏幕一闪一闪的。。

我重装系统吧 ,换了windows10.
然后装Anaconda3。
地址1: https://repo.continuum.io/archive/
地址2:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

conda --version 检查anaconda的安装与环境变量配置是否成功
执行命令conda create --name python35 python=3.5
报错condaHTTPError+sslerror:

https://blog.csdn.net/qq_41761293/article/details/86988511
https://blog.csdn.net/ebzxw/article/details/80702506

使用conda env list 时报错,显示LoadError: Load Error: in /home/li/.condarc on line 5, column 0. Invalid YAML,删掉.condarc文件后不报错。
https://blog.csdn.net/weixin_40533355/article/details/88737415

打开anaconda prompt

conda activate python35 进入python35环境下

python
import sys
print(sys.path) 输出python的安装路径

pip install keras
conda install mingw libpython

python
import keras
exit()

这里执行完后conda下的python变成3.7了。。。
直接将现有的anaconda中python更改为3.5,
打开终端,执行指令:sudo conda install python=3.5 (没有用)

在这里插入图片描述
到这里的时候,我还是没有查到怎么把python的版本改回来,而且dos命令提示有个文件出问题了。
我移除了原有的python35,卸载了anaconda的两个软件。
重新安装。见顶部的链接。

在图形管理界面打开spyder,选中自己建立的python35环境,install spyder
https://blog.csdn.net/bin_bin_bingo/article/details/79250591

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值