How to set up Pytorch environment (linux version)

1 Install Anaconda

First open the Anaconda official website and download the installation package for the corresponding platform
Anaconda official website
insert image description here
insert image description here

The package we installed here is Anaconda3-2022.05-Linux-x86_64.sh.
Then, open the terminal, upload the installation package to the server, and run the command

bash Anaconda3-2022.05-Linux-x86_64.sh 

Wait for the installation. After the installation is completed, enter python in the terminal and you should be able to jump to the interpreter:
insert image description here

2 Install Pytorch

Initialize .condarc file

conda config --set show_channel_urls yes

insert image description here

At this point, enter the command ls -alh, you can see that there is already a .condarc fileinsert image description here

Modify the .condarc file as follows:

vi .condarc

PC version

channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/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/pkgs/main/
  - http://mirrors.aliyun.com/anaconda/pkgs/main
  - http://mirrors.aliyun.com/anaconda/pkgs/r
  - http://mirrors.aliyun.com/anaconda/pkgs/msys2
show_channel_urls: true
custom_channels:
  conda-forge: http://mirrors.aliyun.com/anaconda/cloud
  msys2: http://mirrors.aliyun.com/anaconda/cloud
  bioconda: http://mirrors.aliyun.com/anaconda/cloud
  menpo: http://mirrors.aliyun.com/anaconda/cloud
  pytorch: http://mirrors.aliyun.com/anaconda/cloud
  simpleitk: http://mirrors.aliyun.com/anaconda/cloud

Service-Terminal

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_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/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

Create a virtual python environment for pytorch:

conda create -n pytorch python=3.8

insert image description here

Then activate the environment and install pytorch:

conda activate pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

After the installation is completed, you can use the pytorch environment.
insert image description here
insert image description here
Check whether the pytorch environment is installed successfully.

import torch
print(torch.cuda.is_available())
True

Guess you like

Origin blog.csdn.net/weixin_41801682/article/details/125546200