2019最新win10 安装tensorflow1.4(GPU/CPU)+cuda8.0+cudnn8.0-v6 + keras 安装CUDA失败 导入tensorflow失败报错问题解决
原文作者:aircraft
原文链接:https://www.cnblogs.com/DOMLX/p/9747019.html
基本开发环境搭建
1. Microsoft Windows 版本
关于Windows的版本选择,本人强烈建议对于部分高性能的新机器采用Windows 10
作为基础环境,部分老旧笔记本或低性能机器采用Windows 7
即可,本文环境将以Windows 10
作为开发环境进行描述。对于Windows 10的发行版本选择,笔者建议采用Windows_10_enterprise_2016_ltsb_x64
作为基础环境。
这里推荐到MSDN我告诉你下载,也感谢作者国内优秀作者雪龙狼前辈所做出的贡献与牺牲。
直接贴出热链,复制粘贴迅雷下载:
ed2k://|file|cn_windows_10_enterprise_2016_ltsb_x64_dvd_9060409.iso|3821895680|FF17FF2D5919E3A560151BBC11C399D1|/
2. 编译环境Microsoft Visual Studio 2015 Update 3
(安装CPU版本非必须安装)
CUDA编译器为Microsoft Visual Studio,版本从2010-2015,cuda8.0
仅支持2015版本,暂不支持VS2017,本文采用Visual Studio 2015 Update 3
。 同样直接贴出迅雷热链:
ed2k://|file|cn_visual_studio_professional_2015_with_update_3_x86_x64_dvd_8923256.iso|7745202176|DD35D3D169D553224BE5FB44E074ED5E|/
vs2015下载百度云磁力:链接:https://pan.baidu.com/s/1nZk92C-I8oRvxbyjELBNEw 密码:1hnb
3. Python环境
python环境建设推荐使用科学计算集成python发行版Anaconda,Anaconda是Python众多发行版中非常适用于科学计算的版本,里面已经集成了很多优秀的科学计算Python库。 建议安装Anconda3 4.2.0
版本,目前新出的python3.6存在部分不兼容问题,所以建议安装历史版本4.2.0 注意:windows10版本下的tensorflow暂时不支持python2.7
下载地址: Anaconda
创建python虚拟环境。
在CMD执行以下命令创建python版本为3.6、名字为tensorflow的虚拟环境。tensorflow文件可以在Anaconda安装目录envs文件下找到
conda create -n tensorflow python=3.6
这里的tensorflow只是个名字变量而已,可以随意改 比如我的是conda create -n py3 python=3.6
完毕后记得用activate 你的名字变量 进入虚拟环境
比如我的:activate
py3
退出虚拟环境:deactivate
4. CUDA
(安装CPU版本非必须安装) CUDA Toolkit是NVIDIA公司面向GPU编程提供的基础工具包,也是驱动显卡计算的核心技术工具。 直接安装CUDA8.0即可 下载地址:https://developer.nvidia.com/cuda-downloads 在下载之后,按照步骤安装,不建议新手修改安装目录,同上,环境不需要配置,安装程序会自动配置好。
这里可能会出现安装CUDA失败,原因可能是
1.VS2015(或者之前装的VS系列没有卸载干净,建议重装系统hhhhh)没有装
2.没有安装在C盘默认目录(因为这里我装其他盘都会失败,就C盘成功了)
3.从安全模式启动(参见http://www.tudoupe.com/win10/win10jiqiao/2016/1222/6230.html)。在c盘的Program Files和Program Files(x86)两个文件夹中分别删除NVIDIA Corporation和NVIDIA GPU Computing Toolkit(这个没有的话就随意)文件夹。正常模式重启,重新安装即可。 这里可能会出现文件NVIDIA Corporation被占用的情况,进入安全模式删除即可。
6. 加速库CuDNN
从官网下载需要注册 Nvidia 开发者账号,网盘搜索一般也能找到。
CuDNN5.1百度云下载
CuDNN6.1百度云下载
CuDNN9.0百度云三个版本下载都在下面百度云链接里
链接:https://pan.baidu.com/s/1mprpx7iO2CW3Y1xjFQBLzQ 密码:6m6g
本文用的是里面的cudnn8.0-v6版本+tensorflow--1.4+cuda8.0
7. 安装tensorflow
如果原来有安装,卸载原来的tensorflow:pip uninstall tensorflow-gpu
安装新版本的tensorflow:pip install tensorflow-gpu==1.4
这里如果是1.6以上的话CUDNN要9.0的才行1.3以下的话CUDA 和CUDNN都要换版本 具体情况具体百度查对应版本。1.1以下的话好像基本不能GPU运行了
(CPU版本:
pip install --upgrade tensorflow
)CPU版本最简单也适合新手 直接python创建完虚拟环境3.6之后直接安装即可。
pip install tensorflow -i https://pypi.douban.com/simple cpu版本
如果安装过程报错:Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
就直接:python -m pip install --upgrade pip
升级PIP即可
安装完毕开始测试:
首先确保自己进入安装tensorflow的虚拟环境,然后直接 python进入py环境
然后import tensorflow as tf
没有报错的话在输入 tf.__version__
出现版本号即代表成功了
如果import tensorflow as tf 出现错误:
Traceback (most recent call last):
File "C:\Users\****\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\****\Anaconda3\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: 找不到指定的模块。
或者导入tensorflow报错:
ImportError: DLL load failed: 找不到指定的模块。
亦或者导入tensorflow报错:
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.
亦或者导入tensorflow报错:
1、libcudnn.so.x 找不到的情况:没有装 cuDNN
2、libcublas.so.x 找不到的情况:版本不匹配, CUDA与 cuDNN 或者tensorflow 版本不匹配,等等
以上的所有报错我都经历过,并且别人的教程都说是CUDA和CUDNN版本不匹配,或者VS2015/2017没有安装 ,的确是这样的,结果我都试了好多个版本都没有解决。最后发现我的tensorflow是1.1版本的太老了 换成1.4就成功了(2017可能太新不匹配DUDA8.0)
所以解决办法:temsorflow版本+VS2015/2017安装+CUDA版本+CUDNN版本要匹配 中间哪一个版本没匹配都会出现上面的报错。具体情况具体查自己电脑配置的匹配版本 本电脑是1050TI,CPU是志强I5
7. 安装keras
pip install keras -U --pre
然后进入python
import keras
没有报错就代表成功。
如果报错:
Traceback (most recent call last):
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\urllib3\response.py", line 331, in _error_catcher
yield
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\urllib3\response.py", line 413, in read
data = self._fp.read(amt)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "E:\ANDROD\envs\py3\lib\http\client.py", line 449, in read
n = self.readinto(b)
File "E:\ANDROD\envs\py3\lib\http\client.py", line 493, in readinto
n = self.fp.readinto(b)
File "E:\ANDROD\envs\py3\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "E:\ANDROD\envs\py3\lib\ssl.py", line 1002, in recv_into
return self.read(nbytes, buffer)
File "E:\ANDROD\envs\py3\lib\ssl.py", line 865, in read
return self._sslobj.read(len, buffer)
File "E:\ANDROD\envs\py3\lib\ssl.py", line 625, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\basecommand.py", line 141, in main
status = self.run(options, args)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\commands\install.py", line 299, in run
resolver.resolve(requirement_set)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\resolve.py", line 102, in resolve
self._resolve_one(requirement_set, req)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\operations\prepare.py", line 283, in prepare_linked_requirement
progress_bar=self.progress_bar
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 836, in unpack_url
progress_bar=progress_bar
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 673, in unpack_http_url
progress_bar)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 897, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 617, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\utils\hashes.py", line 48, in check_against_chunks
for chunk in chunks:
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 585, in written_chunks
for chunk in chunks:
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\utils\ui.py", line 159, in iter
for x in it:
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_internal\download.py", line 574, in resp_read
decode_content=False):
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\urllib3\response.py", line 465, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\urllib3\response.py", line 430, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "E:\ANDROD\envs\py3\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "E:\ANDROD\envs\py3\lib\site-packages\pip-18.0-py3.6.egg\pip\_vendor\urllib3\response.py", line 336, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
这是因为超时报错,直接:pip --default-timeout=100 install -U Pillow
设置超时时间即可。
若有兴趣交流分享技术,可关注本人公众号,里面会不定期的分享各种编程教程,和共享源码,诸如研究分享关于c/c++,python,前端,后端,opencv,halcon,opengl,机器学习深度学习之类有关于基础编程,图像处理和机器视觉开发的知识