PyTorch development environment installation tutorial under Windows

PyTorch development environment installation tutorial under Windows

Anaconda Installation

Anaconda is a software package created to facilitate the use of Python. It contains more than 250 commonly used toolkits, multiple versions of Python interpreters, and powerful virtual environment management tools, so Anaconda is named the Python family bucket. Anaconda can make installation, operation and upgrade environment easier, so it is recommended to install and use it.

Installation steps:

  • Download the installation package from the official website https://www.anaconda.com/distribution/#download-section
  • Run the installation package
  • Select the installation path: Usually choose the default path, be sure to check Add Anaconda to the system PATH environment variable, and wait for the installation to complete
  • Verify that the installation is successful: Press the shortcut key win+R, open cmd, enter conda, and press Enter. If various related information appears, it means that the installation is successful.

PyCharm Installation

PyCharm is a powerful Python IDE with debugging, syntax highlighting, Project management, code jumping, smart prompts, version control and other functions.

Installation steps:

  1. Download the installation package from the official website https://www.jetbrains.com/pycharm/. The installation package is divided into professional version (paid) and community version (free).
  2. Run the installation package.
  3. Select the path, check Add launchers dir to the PATH, check .py, and wait for the installation to complete.

CUDA and CuDNN installation (optional)

  1. Check whether there is a suitable GPU. If so, install CUDA and CuDNN. Only N cards support cuda. ​​You can view the supported cuda versions by doing the following:
  2. NVIDIA Control Panel → System Information → Components → 3D Settings/NVCUDA.DLL
  3. Go to the PyTorch official website https://pytorch.org/, click GetStarted, and check the supported CUDA version.
  4. Go to the CUDA official website https://developer.nvidia.com/cuda-toolkit-archive, select the corresponding version of CUDA, select the corresponding operating system, and select local for Installer Type. Click to download the first file. Run the installation package and the installation is complete without creating a shortcut.
  5. Verify that CUDA is installed successfully: Go to the bin folder of the installation path, copy the path, switch the command line to the path (for example, cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin), then execute nvcc -V and press Enter. If the relevant version information is displayed, it indicates that it is installed correctly.
  6. Go to the cuDNN official website https://developer.nvidia.com/rdp/cudnn-download, register and log in to your account, and select the corresponding version to download. Unzip the installation package and copy the three folders in it to the CUDA installation path (such as C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1). The cuDNN installation is complete.
  7. Verify whether cuDNN is installed successfully: Switch the command line to the extras\demo_suite folder in the installation path, execute bandwidthTest.exe, press Enter, and Result = PASS indicates that the installation is successful. Continue to execute deviceQuery.exe, press Enter, and the GPU model will be displayed. Result = PASS, indicating that both CUDA and cuDNN are installed successfully.

Change the pip source to the domestic mirror

When using pip to install the Python toolkit, it is recommended to switch to a domestic mirror because the default source network speed is extremely slow.
Default Source

https://pypi.org/

Domestic mirror

Alibaba Cloud https://mirrors.aliyun.com/pypi/simple/

University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/

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

Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/

Huazhong University of Science and Technology https://pypi.hustunique.com/

Temporary use <br />   Just add -i url after the installation command, such as: download pandas using Tsinghua mirror
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
Permanent modification <br /> Modify the %HOMEPATH%\pip\pip.ini file %HOMEPATH% is usually C:\Users\xx
Usually you need to create a new folder pip, and then create a new file pip.ini. The ini file can be opened and edited with Notepad. Enter the following content in the pip.ini file (taking Douban Mirror as an example):

[global]
index-url = https://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com

PyTorch Installation

1. Download whl file (optional)

Go to the PyTorch official website https://pytorch.org/, click GetStarted, select the corresponding version, select pip for package, you can see the latest version numbers of torch and torchvision appear below, as well as a URL https://download.pytorch.org/whl/torch_stable.html, copy the URL and enter, you can see the installation files of various versions of torch. This method is faster than directly executing the installation command. The file naming is regular, such as:

cu101/torch-1.4.0-cp37-cp37m-win_amd64.whl,
cu101/torchvision-0.5.0-cp37-cp37m-win_amd64.whl

The version after cu is cuda, the version after torch is torch, the version after torchvision is torchvision, the version after cp is python, and the last one represents windows 64 bit.

You can use the shortcut key ctrl+F to search for the latest version of torch and torchvision files (such as searching for cu101/torch-1.4.0), and then select the corresponding python version and platform to download the whl files of pytorch and torchvision. The python version must be consistent with the system. You can enter python in the command line to view the python version in the system.

2. Create a new project with PyCharm

Create New Project→Pure Python→Name→Create
Create a new script: File→New→Python file→Name→Enter Enter the following code in the script→Right click→Run 'project name' →Error: torch cannot be found because we have not installed PyTorch in the current environment.

import torch
print("hello pytorch{}".format(torch.__version__))
print(torch.cuda.is_available())

3. Create a Python virtual environment

Click Terminal below → Enter conda create -n virtual environment name python=version number (such as conda create -n pytorch_gpu python=3.7) → Press Enter → Wait for completion

Enter the virtual environment: Enter conda activate virtual environment name → press Enter

4. Installation

Enter the directory where the whl file is located: Enter cd whl file directory → Enter Installation: Enter pip install torch → Press tab to complete automatically → Enter → Wait for successful installation Enter pip install torchvision → Press tab to complete automatically → Enter → Wait for successful installation

Note: If you did not download the whl file in the first step, you can directly install it using pip or conda command. The installation command will be displayed after selecting the corresponding version on the PyTorch official website.

5. Associate the current project with the newly created virtual environment, that is, select the Python interpreter

File→Setting→Project: Project name/Project Interpreter→Setting button→Add→Conda Environment→Existing environment→Select anaconda installation path/envs/virtual environment name/python.exe in interpreter→OK→OK→OK→OK→Wait a moment for initialization

6. Verification

Right click to run and successfully output the PyTorch version. If the output is True, it proves that the GPU is available.

Summarize

This is the end of this article about the installation tutorial of the PyTorch development environment under Windows. For more relevant windows PyTorch environment installation content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to build PyTorch in Windows environment
  • Windows+Anaconda3+PyTorch+PyCharm installation tutorial with pictures and text
  • Detailed installation process of Windows10+anacond+GPU+pytorch
  • Detailed graphic tutorial for quickly installing pytorch on windows system
  • About the installation tutorial of Tensorflow and pytorch under windows
  • Installation and verification of pytorch in linux or windows environment (solving runtimeerror problem)
  • How to install and configure the CPU version of PyTorch under Windows

<<:  Detailed explanation of the mysqlslap command and syntax for the built-in stress test in MySQL 5.7

>>:  react-beautiful-dnd implements component drag and drop function

Recommend

Guide to Efficient Use of MySQL Indexes

Preface I believe most people have used MySQL and...

Processing ideas for decrypting WeChat applet packages on PC in node.js

Table of contents Where is the source code of the...

jQuery realizes the effect of theater seat selection and reservation

jQuery realizes the effect of theater seat select...

An audio-visual Linux distribution that appeals to audiophiles

I recently stumbled upon the Audiovisual Linux Pr...

How to use Portainer to build a visual interface for Docker

Portainer Introduction Portainer is a graphical m...

How to solve the problem that mysql cannot be closed

Solution to mysql not closing: Right-click on the...

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...

MySQL simple example of sorting Chinese characters by pinyin

If the field storing the name uses the GBK charac...

HTML+jQuery to implement a simple login page

Table of contents Introduction Public code (backe...

Implementation of Vue large file upload and breakpoint resumable upload

Table of contents 2 solutions for file upload Bas...

MySql fuzzy query json keyword retrieval solution example

Table of contents Preface Option 1: Option 2: Opt...