@[TOC](在Windows10下用Anaconda创建TensorFlow2.0.0 (CPU+GPU) 虚拟环境)
修改原因是外网下载速度忒慢~
(1)在Anaconda Prompt窗口执行配置命令
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes
(2)修改"C://用户//XX//.condarc"文件,去掉defaults那一行
原始:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- defaults
ssl_verify: true
show_channel_urls: true
修改后:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
ssl_verify: true
show_channel_urls: true
创建tensorflow2.0 CPU版本环境:
conda create -n tensorflow2
激活:
activate tensorflow2
(1)CPU版本Tensorflow2.0
conda install tensorflow
,conda命令默认安装的是tensorflow1.0+版本,tensorflow2.0版本只能用pip19.0+版本安装:正确安装步骤:
1)conda安装python
conda install python
2)升级pip
python -m pip install --upgrade pip
3)pip使用清华源安装TensorFlow2.0.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.0.0
此时出现超时报错:ReadTimeoutError:HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out.
解决:
pip --default-timeout=100 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.0.0
此时可以成功安装,但仍有报错:google-auth 1.13.1 has requirement setuptools>=40.3.0. but you'll have setuptools 36.4.0 which is incompatible.
咱不急,有错就改:
pip install --upgrade setuptools
(2)CPU版本Tensorflow2.0 测试结果
用conda list
检查一下已安装的包:
显示已安装成功,进入python import一下测试:
证明安装没问题
(3)补充其他常用软件包
1)pip安装matplotlib, pandas等等
pip install matplotlib
pip install pandas
(1)首先准备好必需的硬件软件
官网给出的requirements:
下载地址:
CUDA10.1: https://developer.nvidia.com/cuda-downloads
cuDNN7.6: https://developer.nvidia.com/cudnn
(2)CUDA安装
第一次安装选择精简安装,这里选了D盘安装:
- CUDA_BIN_PATH = %CUDA_PATH%\bin
- CUDA_LIB_PATH =%CUDA_PATH%\lib\x64
- CUDA_CUPTI_PATH =%CUDA_PATH%\extras\CUPTI\lib64
- CUDA_SDK_PATH = D:\ProgramData\NVIDIA Corporation\CUDA
Samples\v10.1- CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64%
- CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64
设置完后,用cmd命令来检查
Result=PASS代表成功
(3)配置cuDNN
把下载好的压缩文件解压,把三个文件夹复制到CUDA_PATH中
配置完了记得重启电脑!!!
参考链接:https://blog.csdn.net/qq_27825451/article/details/89082978
说明:
(4)用Anaconda新建一个虚拟环境
创建tensorflow2.0 GPU版本环境:
conda create -n tensorflow2-gpu
激活环境
activate tensorflow2-gpu
(5)pip安装tensorflow-gpu==2.1.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow_gpu==2.1.0
(6)测试
在Anaconda Prompt中进入python执行import tensorflow
,出现错误:
ImportError: DLL load failed: 找不到指定的模块。
查到原因可能是没安装Visual Studio:
按照指示安装并重启电脑后,重新测试:
可以正常import了!!!!激动撒花~~