Pytoch environment construction (WIN10)


)

catalogue

If you have any questions, please point them out! Reprint please indicate the source!

Anaconda installation

Here we use Tsinghua mirror source , select 64 bit or 32-bit to download (otherwise an error will be reported). The installation process defaults to the next step (the installation location can be selected by yourself).
After installation, open Anaconda prompt (Anaconda 3)

Enter conda. If the following information is prompted, the installation is successful

Anaconda environment configuration

Right click this computer
Select advanced system settings
Select Advanced
Select environment variable
Double click path

add to

D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin

(find your own installation path, copy and add)

Graphics card configuration (skip this step if there is no Nvidia graphics card)

We use the shortcut key Ctrl+Alt+Delete to open the task manager and select performance, as shown in the following figure.

Click GPU, and your graphics card model is in the upper right corner. We need to update the graphics card driver (very important!!!)
We enter NVIDIA official website , select your own graphics card model
As shown in the figure below, click search to download and install.

Create a python environment

We enter cmd in Win+R to open the console, and then enter

conda create -n pytorch python=3.8

Create a python environment and enter y when prompted to continue the installation.
(3.8 is your own python version. You can enter python on the console to view it by yourself)
After installation, enter

conda info --envs

The following figure shows the environment to be created (I have three environments here)

input

conda activate pytorch

You can enter the pytorch environment we created

Preparation before installation (source replacement)

reference resources Blog , we can find one in the home directory (windows: C:\users\username \) condarc, open it in Notepad mode and replace the contents with

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

that will do

Install pytoch

We enter pytorch official website , select as shown in the figure below. If there is no graphics card, select CPU


If there is a graphics card, open Anaconda prompt (Anaconda 3), enter the pytorch environment you created, and enter

nvidia-smi

Check your CUDA version number (if the graphics card is not configured, please configure the graphics card first), as shown in the figure below. My version is 11.5, so I choose cuda11 three

Copy the command line generated on the official website and enter the python environment for installation. My command behavior

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

I have referred to many blogs here. Removing - c pytorch after the command line can reduce many errors, so the final command behavior

conda install pytorch torchvision torchaudio cudatoolkit=11.3

Enter y to install as prompted

Verify that the installation was successful

Enter in your pytorch environment

python

Import package

import torch

input

torch.cuda.is_available()

If return figure, pytorch is installed successfully and can be used normally.

Return False

reference resources Blog
Most of the problems of returning false can be solved.

Other error reports

Error about conda installation environment: Solving environment: failed with initial frozen solve
reference resources Blog

Keywords: Python Pytorch Deep Learning

Added by webtuto on Fri, 14 Jan 2022 18:04:42 +0200