Linux服务器配置深度学习环境

一、安装Anaconda

依次执行以下语句,需要下载安装包,并直接bash安装,而不是pip或apt-get

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.1.0-Linux-x86_64.sh 
bash Anaconda3-5.1.0-Linux-x86_64.sh

安装完成之后,需要使用

source ~/.bashrc

命令重启一下环境变量

正常情况下就可以使用conda了

conda -V #用于检测是否成功安装conda,打印版本号则证明成功

若到这一步仍提示command:conda not found则需进入.bashrc重新设置一下环境变量,步骤如下。

vim ~/.bashrc

(没有vim的话,apt-get装一下vim即可)

在.bashrc文件中加入以下这句

export PATH=$PATH:/root/anaconda3/bin

保存退出后

source ~/.bashrc

 

二、使用conda创建环境

conda create -n pytorch python=3.6 
conda activate pytorch

这样就创建了一个名为pytorch的基于python3.6的conda环境了

三、在conda环境中安装torch

查看服务器上的GPU配置

有没有gpu?nvidia-smi命令

 

cuda版本?

还是上面那个命令,表格第一行写了,CUDA Version: 11.6。

安装命令

conda install pytorch torchvision torchaudio cudatoolkit=11.6

给conda设置国内源

使用默认的源安装会特别特别慢。

补充知识(案例):

例如conda添加清华源

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

例如conda清除国内源

conda config --remove-key channels

例如Anaconda 查看安装源:

conda config --show-sources

操作办法:

办法一:

添加清华源(为Conda添加清华软件源 - 知乎

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/ # 以上两条是Anaconda官方库的镜像 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ # 以上是Anaconda第三方库 Conda Forge的镜像 # for linux 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ # for legacy win-64 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/ # 以上两条是Pytorch的Anaconda第三方镜像 
conda config --set show_channel_urls yes
  • 重新安装:
conda install pytorch torchvision torchaudio cudatoolkit=11.6

一直CondaHTTPError: HTTP 000 CONNECTION FAILED for url [https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json](https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json) Elapsed: -

去掉默认channel(-default)

执行安装命令:

conda install pytorch torchvision torchaudio cudatoolkit=11.6

安装成功。

办法二:

推荐第一步配置conda为清华源:

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/pkgs/free/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/ 
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ 
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ 
conda config --set show_channel_urls yes

修改conda配置信息:

vim ~/.condarc

改为:关键点 删除 - defaults 增加 ssl_verify: false,如果不太清楚如何修改,直接把下方内容替换掉~/.condarc中的内容

channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ 
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ 
show_channel_urls: true 
ssl_verify: false

保存以后就可以了。

执行安装命令:

conda install pytorch torchvision torchaudio cudatoolkit=11.6

安装成功。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

』探索『

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值