Python installation Pytorch tutorial (detailed graphic and text)
Recently, many courses such as artificial intelligence need to reproduce papers. Many of the papers in the past two years are in the Pytorch environment. Therefore, here is a summary of the installation tutorial of Pytorch, and the fastest, easiest, and best way to complete the installation.
native environment |
---|
Win10+1050Ti+Python3.7 |
1. Check the CUDA version of the machine
cmd command line inputnvidia-smi
, you can see the version number of CUDA on the far right of the first line, my version is 11.1
2. Install Pytroch
1. Click to enter the Pytorch official website
and then select Get Started, which is the following interface
2. Here is the choice of Pytorch version,First, I chose the Stable version, then the OS is Windows, and the Package package uses Conda. The Language must choose Python, and the final Compute Platform is determined according to your needs.
If you want to run the code on your own computer (with NVIDIA graphics card), choose CUDA. If you don't need to run on your own computer (run on a server) or don't have a discrete graphics card, choose CPU.
We have already seen the CUDA version of our own NAVIDA in the first step, here we must choose a CUDA version lower than our own. For example, if my version is 11.1, then I can only choose 10.2, because 11.3 is a bit high. For the same reason, basically everyone can choose 10.2.
If you don't have anaconda installed, you can refer to my blog: anaconda installation and configuration tutorial
If you want to install Pytorch through pip, I can tell you that it is almost impossible to install through pip, and it takes far more time than installing anaconda. Therefore, I will help you detect this detour first, don't step on it again, anaconda It is really a must-have artifact for deep learning.
3. Then copy the command line statement at the bottom, open the anaconda command line, first enter the environment where you need to install Pytorch, and then run it.
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
- 1
4. You can see that there are Pytorch and cudatoolkit in the package to be installed. We enter y to confirm, and then press Enter
. 5. Next, wait for these packages to be installed successfully. You can see that Pytorch is still relatively large, so wait patiently.
6. After the installation is complete, the message done will be prompted.
7. Enter pip list to see if our package is installed. Here you can see that torch -related packages are installed.
8. We enterpython
Enter the Python environment and enterimport torch
, if no error is reported, the import can be successful.
9. Inputtorch.cuda.is_available()
Check if the torch can use the graphics card, True means yes!
CUDA (Compute Unified Device Architecture) is a computing platform launched by the graphics card manufacturer NVIDIA. CUDA™ is a general-purpose parallel computing architecture introduced by NVIDIA that enables GPUs to solve complex computing problems. It contains the CUDA instruction set architecture (ISA) and the parallel computing engine inside the GPU. Developers can use the C language to write programs for the CUDA™ architecture that run at ultra-high performance on CUDA™-enabled processors.