Pytorch服务器安装步骤和常用指令

1. 安装Anaconda

bash Anaconda3-2019.10-Linux-x86_64.sh

2. 创建虚拟环境

不同的代码需要不同版本的Python或Pytorch,使用虚拟环境是有必要的。

  1. 创建虚拟环境conda create -n your_env_name python=X.X
conda create -n py3.6-torch1.3 python=3.6
  1. 激活虚拟环境conda activate your_env_name
conda activate py3.6-torch1.3
  1. 退出虚拟环境conda deactivate
  2. 删除虚拟环境conda remove -n your_env_name --all

3. 安装Pytorch

3.1 确定CUDA版本

查看服务器系统CUDA版本的方法:

  • cat /usr/local/cuda/version.txt
  • nvcc -V
    只有安装了nvidia-cuda-toolkit才可以使用nvcc -V
cat /usr/local/cuda/version.txt
# CUDA Version 10.0.130

系统的CUDA版本必须和Pytorch的CUDA版本对应,比如pytorch0.4最高支持cuda9.2,那么在CUDA10.0以上的系统中不能安装pytorch0.4。

3.2 添加清华镜像源

使用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/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

conda config --set show_channel_urls yes:从channel中安装包时显示channel的url,即显示包的安装来源。

  • 查看channel信息:conda config --show channels
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
  • 移除镜像源可以输入:conda config --remove channels http_ulr(需要删除的channel)

3.3 Pytorch安装

根据自己系统的环境,在pytorch官网寻找合适的命令:

conda install pytorch torchvision cudatoolkit=10.0

如需指定版本:conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch
注意:-c pytorch参数指定了pytorch的安装来源,即为自带的pytorch仓库,因此,将-c pytorch去掉,安装时会选择清华镜像源作为安装来源。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值