一键安装深度学习环境(tensorflow, pytorch)

Anaconda安装

下载地址:

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

配置conda清华源

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

或者

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

window系统为:
第1步:进入C:\Users\Administrator(这里的Administrator可以是你的用户名)
第2步:记事本方式打开.condarc文件
第3步:插入上面第一个的指令。

  • 北外镜像
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free/ 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/ 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
  • 中科大镜像
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes

配置pip清华源

打开终端输入以下命令,如果不存在隐藏的pip文件夹,则创建它:

mdir ~/.pip

进入该文件内:

cd ~/.pip

创建pip.conf文件:

touch pip.conf

编辑pip.conf文件:

sudo gedit ~/.pip/pip.conf

在pip.conf文件中写入如下内容,换为清华源,然后保存并退出文件

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ 
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

换为豆瓣源:

[global]
index-url = http://pypi.douban.com/simple/
[install]
trusted-host = pypi.douban.com

输入以下命令查看是否换源成功:

pip config list

CUDA和cuDNN安装

详见:https://blog.csdn.net/BigData_Mining/article/details/99670642
1.下载CUDA (cuda_版本_linux.run文件)
在这里插入图片描述
2.安装CUDA
在这里插入图片描述
3.添加环境变量

vi ~/.bashrc

在文件末尾添加

export PATH="/usr/local/cuda-10.1/bin:$PATH"
exportLD_LIBRARY_PATH="/usr/lcoal/cuda10.1/lib64:$LD_LIBRARY_PATH"

最后使其生效

source ~/.bashrc

4.安装cuDNN

地址:https://developer.nvidia.com/rdp/cudnn-archive
在这里插入图片描述

Window 安装 cuda11

  1. 下载exe
    https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_456.43_win10.exe
    【若原始电脑已经安装有VS,则需要在安装选项中选择自定义,取消 CUDA -> Visual Studio Integration选项】
  2. 下载cuDNN
    https://developer.nvidia.com/rdp/cudnn-archive

https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.0.3.33/11.0_20200825/cudnn-11.0-windows-x64-v8.0.3.33.zip

  1. 解压缩
    复制到bin include lib文件夹到 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1

Conda 一键安装tensorflow

直接使用conda安装

conda create -n tf15 python=3.6 tensorflow-gpu=1.15

Conda 一键安装pytorch

直接使用conda安装

conda create -n pytorch1.5 python=3.6 pytorch=1.5 torchvision=0.6

如果先安装python,则需要制定cuda版本:

conda install pytorch torchvision cudatoolkit=10.2

Pytorch 所有版本下载地址:https://download.pytorch.org/whl/torch_stable.html

Pytorch 和 Torchvision版本对应:
在这里插入图片描述

安装其他包

加速下载,pip的时候使用清华源下载:

pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

解决timeout

pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.13.1

若tensorflow和CUDA, CUDNN版本安装不对应,
最好的解决方法是重新使用上述的快速安装策略重新安装,这样也能做到tensorflow和pytorch都可以用。

问题 CondaHTTPError: HTTP 000 CONNECTION FAILED for url
答:通常是conda源的问题,更换下载不了的源即可,目前清华和中科大的源下载不了,北师大的镜像源可以快速下载。

参考

安装两个CUDA
[1] https://blog.csdn.net/BigData_Mining/article/details/99670642
conda自动安装CUDA和cuDNN等库
[2] https://blog.csdn.net/weixin_38383877/article/details/103010143
Ubuntu18.04下安装Nvidia驱动和CUDA10.1+CUDNN,卸载原始显卡驱动,安装新的驱动,CUDA,cuDNN。
[3] https://blog.csdn.net/ksws0292756/article/details/80120561

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值