一、Anaconda安装
下载地址:https://www.anaconda.com/products/individual
安装Anaconda之后就自带python3.7
二、CUDA10.0安装
其实感觉CUDA10.1更好点,但因为之前安装过10.0,也就懒得改了
下载地址:https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
安装细节可以参考我之前安装CUDA9.0的步骤,一般没什么问题
如果是安装tensorflow1,这里需要注意的是CUDA和tensorflow版本要求比较严格,具体对应关系
三、tensorflow2.1GPU版本
打开Anaconda Prompt
创建虚拟环境(可以指定python版本,此处用3.6,主要是因为感觉python3.7用的人少,还是喜欢用旧的版本,因人而异)
conda create -n tensorflow python=3.6
激活虚拟环境(退出conda deactivate)
conda activate tensorflow
安装tensorflow(不同系统,python版本对应的下载地址可以参考网址)其他版本的tensorflowGPU版本下载地址 && CPU版本下载地址
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.1.0-cp36-cp36m-win_amd64.whl
可能出现的问题
问题一:pip安装显示网络异常WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError(‘Cannot connect to proxy.’, NewConnect。。。。。。。。。
解决方法:换个下载源,在C:\Users\用户名\AppData\Roaming新建一个pip文件夹(本文路径如下),并在文件夹底下建立pip.ini文件,使用记事本打开pip.ini
在pip.ini输入如下信息:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
问题二:ImportError: DLL load failed: 找不到指定的模块。
问题如下:主要原因是因为tensorflow2.1与visual studio2019的环境有所依赖
解决方法(方案三最佳,也是本文采用的方法):
- tensorflow降低版本,换成2.0
- vs升级为2017或2019
- vc_redist下载及安装,下载地址:https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported-visual-c-downloads
下载后,右键管理员运行,安装就好了,可能需要重启电脑使其生效
>>> import tensorflow
Traceback (most recent call last):
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\Anaconda3\envs\tensorflow\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\Anaconda3\envs\tensorflow\lib\imp.py", line 343, 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 "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
from tensorflow_core import *
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
from . _api.v2 import audio
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\audio\__init__.py", line 10, in <module>
from tensorflow.python.ops.gen_audio_ops import decode_wav
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\gen_audio_ops.py", line 9, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "D:\Anaconda3\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\Anaconda3\envs\tensorflow\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\Anaconda3\envs\tensorflow\lib\imp.py", line 343, 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.
问题三:Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
这个主要是因为CUDA版本的问题,cudart64_101.dll是CUDA10.1版本的,需要自己下载,手动添加到对应路径下“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin”
下载地址
再次运行import tensorflow,不报错即可