Installation of Python + CUDA + pytorch in window

Time:2021-4-19

1 Overview

WindowslowerPython+CUDA+PyTorchInstallation, steps are very detailed, hereby recorded, to help readers avoid detours.

2 Python

PythonThe installation of is relatively simpleOfficial websitedownloadexeInstall the package:

Installation of Python + CUDA + pytorch in window

Because the latesttorchVersion only supports toPython 3.8Therefore, in order to avoid version compatibility problems, it is recommended to installPython 3.8

Download the one in the middleexecutable installerIt is recommended to select custom:

Installation of Python + CUDA + pytorch in window

Select the required components:

Installation of Python + CUDA + pytorch in window

Select location:

Installation of Python + CUDA + pytorch in window

Installation of Python + CUDA + pytorch in window

After installation, you can check whether the installation is successful from the command line (generally, the path will be added to the environment variable by default)

python --version

Installation of Python + CUDA + pytorch in window

Because the installation package will automaticallypipIt is also installed together, so you will be prompted when using itpipTo upgrade, please use the following commandpip

python -m pip install --upgrade pip

Installation of Python + CUDA + pytorch in window

Before installation, it is recommended to add a domestic source and create a new one in the user directorypipFolder and create a new one calledpip.iniInput the following contents:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

3 CUDA

CUDAIt’s not difficult to install, generallyWindowsWhen installing the system, it will automatically install the correspondingN cardDrive, fromOfficial websiteDownload the correspondingCUDA Toolkit

Installation of Python + CUDA + pytorch in window

Open it after downloading (it is actually a compressed package, here is the decompression path)

Installation of Python + CUDA + pytorch in window

Installation of Python + CUDA + pytorch in window

After decompression, the installation interface will be opened automatically

Installation of Python + CUDA + pytorch in window

If there is no special requirement, you can directly use the default installation option. Otherwise, please select custom components to install

Installation of Python + CUDA + pytorch in window

Because I didn’t install itVS, which will prompt that it cannot be foundVS, ignore:

Installation of Python + CUDA + pytorch in window

The next step is to wait for the installation:

Installation of Python + CUDA + pytorch in window

Installation of Python + CUDA + pytorch in window

Installation complete:

Installation of Python + CUDA + pytorch in window

opencmdinputnvcc --versionThe installation is successful when the version number is displayed

Installation of Python + CUDA + pytorch in window

4 PyTorch

4.1 download

PyTorchOffline manual installation is recommended,Poke hereDownload correspondingCUDAVersion and correspondencePythonVersion oftorchas well astorchvision

Installation of Python + CUDA + pytorch in window

The frontcu110expresscuda 11.0And thentorch/torchvisionAnd then there’s the version, the followingcpexpressPythonVersions, such ascp36expressPython 3.6And then the system and architecture.

4.2 installation

Use after downloadpipJust install it

pip install torch-1.7.0+cu110-cp38-cp38-win_amd64.whl
pip install torchvision-0.8.1+cu110-cp38-cp38-win_amd64.whl

Installation of Python + CUDA + pytorch in window

Note that if it isWindows 2004Version may have the following problems:

Installation of Python + CUDA + pytorch in window

This isnumpy 19.0.4Version of the problem, details can be foundPoke here

The solution is to install19.0.3edition:

pip uninstall numpy
pip install numpy==19.0.3

Then test it and turn it onpython

python
import torch
print(torch.__version__)

outputtorchVersion indicates success:

Installation of Python + CUDA + pytorch in window