参考 :
Anaconda Tensorflow GPU 版本的安装问题
https://blog.csdn.net/u010977034/article/details/62038698
Windows10环境下安装Anaconda和tensorflow-gpu,然后在jupyter notebook上使用
https://blog.csdn.net/qq_37392244/article/details/85003425
利用conda安装指定版本的tensorflow
Tensorflow-gpu搭建CUDA 10.0与cuDNN等版本问题
查询Tensorflow与CUDA/CuDNN的版本关系
查询官网说明:
https://tensorflow.google.cn/install/source_windows
查询CUDA要求的GUP Driver Version
查询官网说明:
确定并安装需要的各个版本
python-3.6
tensorflow-gpu-1.13
cuda-10.0
cudnn-7.5
CUDA下载地址: https://developer.nvidia.com/cuda-toolkit-archive
CuDNN下载地址:https://developer.nvidia.com/rdp/cudnn-download
(下载CuDNN需要注册账号,注册过程比较简单)
说明:本次安装的tensorflow需要与Jupyter notebook集成,所以此处只安装CUDA和CuDNN(安装前确保GPU驱动已经安装且版本一致)。
CUDA是NVIDIA推出的运算平台,CuDNN是专门针对Deep Learning框架设计的一套GPU计算加速方案。在安装之前要查询下最新TensorFLow发行版支持到了哪个版本。另外,也要确认CUDA版本是否支持自己的显卡。
安装好CUDA后,再将下载好的cudnn文件解压缩,得到一个文件夹:
将里面的三个文件夹复制到C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.0中
Anaconda的下载和安装
安装Anaconda(一个开源的Python发行版本)的最新版本。Anaconda包含了conda、Python等180多个科学包及其依赖项,功能强大。
Anaconda下载地址:https://www.anaconda.com/download/
本次安装 的是Anaconda3-2018.12-Windows-x86_64,以下截图来自上述博客,主要用于说明有关的设置:
创建tensorflow环境
1、打开Anaconda Prompt
2、建立一个conda环境,命名为tensorflow_gpu
执行:conda create -n tensorflow_gpu python=3.6
3.进入到tensorflow_gpu环境中,在这个环境下面完成之后tensorflow-gpu的安装。
进入创建好的环境中,执行命令:activate tensorflow_gpu
安装tensorflow-gpu,执行命令:conda install --channel https://conda.anaconda.org/anaconda tensorflow-gpu
(该命令的查询方式,见下附【在Anaconda如何确定要安装的tf-gpu版本】)
查看tensorlfow的版本:
为了后面安装的tensorflow-gpu可以在jupyter notebook中使用 ,需要安装这两个包,用conda命令安装:
-
conda install ipython
-
conda install jupyter
执行命令:ipython kernelspec install-self --user
看到类似这个结果:Installed kernelspec python3 in C:UsersXXXJupyterkernelspython3
然后就可以使用jupyter notebook了,使用的时候先用activate tensorflow_gpu命令打开建立的环境,然后再用jupyter notebook命令打开jupyter notebook就可以了。
4、jupyter notebook的使用
打开终端Anaconda Prompt,然后输入activate tensorflow_gpu,进入创建好的环境中,再用jupyter notebook命令打开jupyter notebook即可。
5、修改notebook文件的存放目录
执行命令: jupyter notebook --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --notebook-dir='C:\Users\dell\MyJupyterCode'
在Anaconda如何确定要安装的tf-gpu版本
参考:https://blog.csdn.net/u010977034/article/details/62038698
1、打开终端Anaconda Prompt,执行命令:anaconda search -t conda tensorflow
此指令会查询conda环境中有哪些tensorflow安装包,通过查看版本,选择最高的版本安装。如下图
2、此处查询到的最高版本是 anaconda/tensorflow-gpu 1.13.1,则执行命令:anaconda show anaconda/tensorflow-gpu
这个命令令会告诉你怎么安装这个包
3、根据提示,在终端执行:
conda install --channel https://conda.anaconda.org/anaconda tensorflow-gpu
4、在第1步中可以看到,anaconda/tensorflow-gpu 带着版本号 1.13.1。因此,如果有多个版本,而你想安装一个指定的版本,则应该在命令后面加入版本信息,如:
conda install --channel https://conda.anaconda.org/anaconda tensorflow-gpu=1.13.1
如何删除已经建立 的conda环境
执行命令:
-
deactivate tensorflow_gpu
-
conda remove -n tensorflow --all
-
conda info --envs
遇到的问题
第一次安装后,在jupyter book中运行import tensorflow as tf时,报错。
重要的报错信息是:ImportError: DLL load failed: 找不到指定的模块。ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
解决方案:
Anaconda中安装 的tensorflow-gpu版本太低,与CUDA/Cudnn不匹配,重新按上述方法选择13.1安装即可。
--------------------详细报错信息如下-------------------------------------------------------
ImportError Traceback (most recent call last)
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py in swig_import_helper()
17 try:
---> 18 return importlib.import_module(mname)
19 except ImportError:
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\__init__.py in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
127
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in _gcd_import(name, package, level)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in _find_and_load(name, import_)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in _find_and_load_unlocked(name, import_)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in _load_unlocked(spec)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in module_from_spec(spec)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap_external.py in create_module(self, spec)
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
ModuleNotFoundError Traceback (most recent call last)
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow.py in <module>()
40 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 41 from tensorflow.python.pywrap_tensorflow_internal import *
42 from tensorflow.python.pywrap_tensorflow_internal import __version__
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py in <module>()
20 return importlib.import_module('_pywrap_tensorflow_internal')
---> 21 _pywrap_tensorflow_internal = swig_import_helper()
22 del swig_import_helper
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py in swig_import_helper()
19 except ImportError:
---> 20 return importlib.import_module('_pywrap_tensorflow_internal')
21 _pywrap_tensorflow_internal = swig_import_helper()
~AppDataLocalcondacondaenvs ensorflow_gpulibimportlib\__init__.py in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
127
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflow\__init__.py in <module>()
22
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import
26
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpython\__init__.py in <module>()
49 import numpy as np
50
---> 51 from tensorflow.python import pywrap_tensorflow
52
53 # Protocol buffers
~AppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow.py in <module>()
50 for some common reasons and solutions. Include the entire stack trace
51 above this error message when asking for help.""" % traceback.format_exc()
---> 52 raise ImportError(msg)
53
54 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibimportlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
File "<frozen importlib._bootstrap>", line 560, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:UsersdellAppDataLocalcondacondaenvs ensorflow_gpulibimportlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: 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.