pip offline installation windows version torch

foreword

When I was studying, I encountered several projects related to machine learning. Since the dependent libraries used by different projects were not the same, I wanted to use conda to create different environments for different projects to facilitate management and operation. The result was installed in torch. Time to pretend for a long time, shallow record

conda

The introduction and usage of conda will not be repeated here. You only need to guide conda to create different virtual environments, so that projects with different dependencies or conflicts can run independently in their respective virtual environments. For relevant information, you can refer to the following blog posts:

Conda installation and use

Create a virtual environment

After configuring the environment variables of conda, you can create a virtual environment through the following command. Here, python3.8 is used as an example, and name is the name of the created environment:

conda create -n [name] python=3.8
#例如
conda create -n skincare python=3.8

Activate the environment, use the activate command under cmd to open the conda environment

activate [name]

insert image description here
Anaconda also provides a visual interface
insert image description here

install torch

When installing torch, it is best to be able to think clearly whether the machine learning project is run with CPU or GPU. Here, the author uses GPU as an example to show the installation process. First, use the nvidia-smi command to check the relevant information of the GPU on the machine
. The key is the CUDA version. For example, the highest supported CUDA version here is 11.6. When installing torch, you can try to select cu116 or below.
insert image description here

Torch official website online installation

Select torch’s operating system, installation method, installation version and other information on the official website, and copy the installation command to install
insert image description here
online. The requirements for the network environment are relatively high, especially when the installation file is relatively large, so if multiple online installations fail You can try offline manual installation

Offline manual installation

Open the URL: https://download.pytorch.org/whl/torch_stable.html
insert image description here
The main thing to pay attention to is to choose the appropriate version, cpu means CPU version, cuxxx means CUDA version, cp37 means python3.7 version, choose torch corresponding Download the version number and operating system version.
According to the installation command on the torch official website, the author downloaded the three installation files of pytorch, torchvision, and torchaudio
insert image description here
. .If you use the conda virtual environment, you need to open and enter the environment before installing)
insert image description here

Test whether the installation is successful

Open the python interpreter, if the import library does not report an error, the installation is successful
insert image description here
Check whether the GPU is available

print(torch.cuda.is_available())

View torch version

print(torch.__version__)

insert image description here
So far the installation is complete

postscript

If you have any questions, please leave a comment or contact me

Guess you like

Origin blog.csdn.net/monster663/article/details/128613693