1.下载Anaconda: https://www.anaconda.com/distribution/#download-section.
#下载最新版本安装后可能出现安装不完全,丢失conda.exe的情况,去网上找之前的版本安装或者使用Miniconda安装
2.Pytorch和torchvision下载与离线安装:
在线安装:pip install pytorch/pip install torchvision
离线安装:
下载地址(清华开源镜像网):https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
命令行在下载目录下运行离线安装指令:pip install torch-1.2.0-cp37-cp37m-win_amd64.whl(名称根据下载版本变化)
pip install torchvision-0.4.0-cp37-cp37m-win_amd64.whl
##检验是否安装成功:在python交互模式下导入torch和torchvision不报错
3.安装CUDA和CUDNN: tensorflow gpu-1.14只能支持到cuda10.0,安装10.1会报错
CUDA下载地址:https://developer.nvidia.com/cuda-10.0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
cuDNN下载地址:https://developer.nvidia.com/rdp/cudnn-archive (选择与CUDA对应的版本)
#查看电脑显卡驱动以及cuda支持型号:Nvidia控制面板—系统信息—组件—NVCUDA.DLL
4.下载和配置libtorch :
下载地址:https://download.pytorch.org/libtorch/cu100/libtorch-win-shared-with-deps-1.2.0.zip(release版)
https://download.pytorch.org/libtorch/cu100/libtorch-win-shared-with-deps-debug-1.2.0.zip(debug版)
#编译遇到缺少.dll错误:在环境变量中添加libtorch中动态链接库的路径如E:\Libtorch\libtorch-win-shared-with-deps-debug-1.2.0\libtorch\lib
5.安装tensorflow cpu版/gpu版:
在线安装:pip install tensorflow/pip install tensorflow-gpu
离线安装:
下载地址:https://pypi.org/project/tensorflow/#files
在下载目录下运行pip install XXXXX.whl
##tensorflow1.14 gpu版只支持cuda10.0,安装10.1版本导入时会报错
安装时可能会遇到的错误:
1.遇到ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
输入 pip install -U --ignore-installed wrapt enum34 simplejson netaddr
2.遇到ERROR: tensorboard 1.14.0 has requirement setuptools>=41.0.0, but you'll have setuptools 39.1.0 which is incompatible.
更新setuptools版本 输入 pip install --upgrade setuptools
3.遇到因numpy报错:ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
可能是numpy版本和当前Tensorflow版本兼容性问题,更新numpy: pip install --user --upgrade numpy。或者卸载再重新安装numpy(如果第一次卸载后安装时显示已安装,再运行一次卸载指令就行)
检测tensorflow gpu版是否安装成功:
运行以下代码
import tensorflow as tf
import tensorflow as tf # 测试
hello =tf.constant("Hello!TensorFlow")
sess = tf.Session()
print(sess.run(hello))
在窗口能够看到自己电脑的显卡名称说明安装成功