1,查看自身服务器版本型号

查看时x86还是arm的

uname -m

这里你会有你可以–help查看更多参数,包括是什么操作系统

uname --help

在这里插入图片描述
查看os的版本号,不知道参数同上–help查询,笔者这里os是ubuntu20.04.2

lsb_release -a

在这里插入图片描述

2、Anaconda安装包下载

这里两种方式自选
(1)下载本地,然后上传到服务器
(2)下载命令行下载
到下面网站上找到合适版本的anaconda
看个人网络情况,国内想快一点就选清华镜像吧没差的。
链接: 官网链接
链接: 清华园镜像
如果是其他版本,选一个你想要的anaconda版本即可。
(可选)
网速好你也可以直接下
比如可以选择Anaconda3-2020.11-Linux-x86_64.sh这个版本的anaconda,然后通过下面命令进行下载

wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh

3、安装Anaconda

进入文件目标文件夹 cd ~/yourdir

bash Anaconda******************-Linux-x86_64.sh
我这里是

bash Anaconda3-2022.10-Linux-x86_64.sh

其实你可以自己tab出来
无脑回车和yes键,按q跳过阅读。
默认安装在用户目录下,直接回车即可安装;若想自定义安装目录,直接输入安装目录,回车即可, 等待一会安装完成。
在这里插入图片描述
当然我这里也给你提供了保险
搞错了卸载直接删了重搞也行

rm -rf ~/anaconda3

4、修改环境变量

将Anaconda添加到用户环境变量中vim ~/.bashrc添加下面内容

export PATH="~/anaconda3/bin:$PATH"

source一下

source ~/.bashrc

4、检查是否安装成功

conda --version

5、换为清华源

(这里我没试,大概这样,可以查一下别人的博客,网速不是太拉换不换都行)

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/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

6、 创建anaconda虚拟环境

conda create -n your_env_name python=X.X(3.6、3.7等)
#第一次激活虚拟环境需要用source
source activate your_env_name(虚拟环境名称) 
#激活虚拟环境
conda activate your_env_name(虚拟环境名称)
#退出虚拟环境
conda deactivate
#查看当前存在哪些虚拟环境
conda env list
#删除虚拟环境
conda remove -n your_env_name(虚拟环境名称) --all
conda remove --name your_env_name package_name  # 删除环境中的某个包
#查看安装了哪些包
conda list
#安装包
conda install package_name(包名)
conda install scrapy==1.3 # 安装指定版本的包
conda install -n 环境名 包名 # 在conda指定的某个环境中安装包
#检查更新当前conda
conda update conda
#更新anaconda
conda update anaconda
#更新所有库
conda update --all
#更新python
conda update python
安装requirements.txt依赖:
pip install -r requirements.txt

7、安装pytorch

进入pytorch官方网站获取安装指令
https://pytorch.org/
在这里插入图片描述

在官网主页根据你的系统和CUDA,python版本,选择conda安装方式。我的是

conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch -c nvidia

最好是重连一下,再在编译器里选择内核测试。有时候直接看可能没同步
测试:
在环境下输入python然后测试

import torch
import torchvision
torch.__version__
torchvision.__version__
torch.cuda.is_available()

8,卸载torch和torchvision

pip uninstall torch
pip uninstall torchvision

9,如何安装与cuda适配的torch?

1.用nvidia-smi查看cuda版本
我这里用的刚才上面的conda create - n pytorch起的名字叫pytorch
在这里插入图片描述

2.在这个官网查找torch版本:https://download.pytorch.org/whl/torch_stable.html
使用以下命令安装

Logo

更多推荐