Methods a

1. Install Anocanda

There are tutorials on the web that I won’t cover here

2. Configure the Tsinghua mirror source


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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

conda config --set show_channel_urls yes
Copy the code

3. Modify the. Condarc file and delete the -defaults line

Condarc: wq! Save and exit

4. Perform the installation

Create the virtual environment first

Conda create -n Torch python=3.6.4 Enter torch as the virtual environment name based on your Python version

Activate the environment

conda activate torch

Executing installation Commands

conda install pytorch torchvision

The installation is successful if the figure above is displayed.

Check whether the installation is successful

import torch
x = torch.rand(5, 3)
print(x)
Copy the code

The results are shown below

Method 2

1. Install Anocanda

There are tutorials on the web that I won’t cover here

Install PyTorch

Go to pyTorch’s website for version selection at pytorch.org/get-started…

Here package selects PIP

The installation command is

PIP install torch = = = 1.9.0 torchvision = = = 0.10.0 -f https://download.pytorch.org/whl/torch_stable.html >

Here the latest version of PyTorch is 1.9.0, so install 1.9.0 as an example

After the install command follow image name -i https://pypi.tuna.tsinghua.edu.cn/simple some package – I followed the name of the mirror, some – package for fixed format.

Here are some mirror sources

Douban (douban) pypi.douban.com/simple/

Tsinghua university pypi.tuna.tsinghua.edu.cn/simple/

Ali cloud mirrors.aliyun.com/pypi/simple…

Pypi.mirrors.ustc.edu.cn/simple/ China university of science and technology

University of science and technology of China pypi.mirrors.ustc.edu.cn/simple/

Tsinghua University and University of Science and Technology mirror source may be wrong, the author tested for many times to install tsinghua mirror source failed, and finally adopted Ali Cloud image installation success.

Ali Cloud is recommended to use the image source, which is the fastest.

The final PIP command is

PIP install torch = = = 1.9.0 torchvision = = = 0.10.0 - https://download.pytorch.org/whl/torch_stable.html - I f http://mirrors.aliyun.com/pypi/simple/ some-package

The installation of pyTorch will be much faster than that of the official website. The following is the process of installing PyTorch. Just wait for the installation to be successful.