ubuntu下Anaconda环境安装GPU的pytorch(docker镜像)

实验室需要给每个人分配docker的container环境,为了节省系统的空间,打算把anaconda和深度学习的开发环境配置好拉取镜像以省时间。

基础环境配置

apt更新了清华源
安装了基础环境
gcc
vim Linux文本编辑库
openssh-server ssh远程连接库
net-tools 包含ifconfig,netstat等指令
iputils-ping 包含ping指令
wget 下载文件指令
curl 网络请求指令
git 版本控制

annaconda配置

官网wget拉取linux的annaconda下载后,bash安装即可(因为实验室服务器没有梯子,个人是下载到了本地然后scp传输到了服务器)

pytorch,cuda,cudnn配置

起初使用annaconda自带的环境,每次配置时间过长,而且一直报错👇

CondaError: Downloaded bytes did not match Content-Length

在安装pytorch的时候安装到半路,显示CondaError: Downloaded bytes did not match Content-Length。

网上的解决方法是添加清华源的镜像,但我的已经是清华源镜像了,所以解决方法是把timeout放大,600还是不行,把时间延长到1000.0就成功安装了。命令如下:

conda config --set remote_read_timeout_secs 1000.0

但是这个解决方法并不是很有效果👆

后来网上查询清华镜像问题,很多都是不全的镜像,安装起来很容易装成cpu版本。

GPU的pytorch安装教程
👆最后采取的这一篇的安装方法。

conda安装踩坑

镜像源如果不全或者当天挂了,容易在找包的时候报错,
个人尝试这个源没问题👇 更换文件使用 vim ~/.condarc 然后把下面的这一坨更换覆盖了就行

channels:
  - defaults
show_channel_urls: true
channel_alias: http://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2

  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

想恢复源 把~/.condarc删除了
然后执行

换回默认源:conda config --remove-key channels

在安装pytorch的时候,首先
官网的推荐链接中
在这里插入图片描述
其中的 -c pytoch -c nvidia 建议去掉 因为有这个会默认按照annaconda的官网地址下载。
更换源之后
可以去搜索一下源是否能下载想使用的包

conda search pytorch
conda search cudatoolkit

下载的时候指令最好是 pytorch和cuda一起安装,要不然会默认安装cpu版pytorch

整体安装流程👇

安装完anaconda后,本地安装的cuda显示正常
在这里插入图片描述

然后换源操作
(base) root@finaltest:~# vim ~/.condarc

在这里插入图片描述

更换后保存退出。输入
conda info查看源已经被替换

在这里插入图片描述
conda search pytorch 看到cloud/pytorch 源已经换成功
在这里插入图片描述
在这里插入图片描述
很奇怪 换到这个镜像后可以找到pytorch-cuda了,直接使用了官网指令,记得去掉后面的-c
conda install pytorch torchvision torchaudio pytorch-cuda=11.8
在这里插入图片描述还是加载不上👆
在这里插入图片描述
在这里插入图片描述

打算安装这个cuda11.8的版本
(base) root@finaltest:~# conda install pytorch=2.1.0 pytorch-cuda=11.8
结果加载过慢,打算换成cudatoolkit
在这里插入图片描述
(base) root@finaltest:~# conda install pytorch=2.1.0 cudatoolkit=11.8.0

如果查询不到或者安装失败 可以看看这个教程 👇
GPU的pytorch安装教程

如果nvcc -V查询不到cuda,使用👇方法

加nvcc环境变量

接下来使用可以用以下指令复制环境,方便对于gpu的使用

conda create -n <new_conda_name> --clone bash

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值