PyTorch is an open source machine learning framework originally from Meta Ai. If you want to study Ai or work on Ai projects, setting up an development env with PyTorch at a local machine is essential for many projects. GPU (Graphics processing unit) is a specialized processor originally designed to process data simultaneously. It helps to speed up computation of your deep learning code. This is a complete guide to install PyTorch GPU on Windows. The installation involves many steps. Let’s get started.
Table of Content
- Download Nvidia graphics driver
- Install Visual Studio Community 2019
- Install CUDA Toolkit 11.8.0
- Install cuDNN 8.6
- Install Anaconda3
- Create virtual environment for TyPorch
- Install PyTorch 2.0
- Run your project
- Install PyCharm
1. Download Nvidia graphics driver
If you already have a PC with GPU, you can skip this step. If you are going to get a new machine learning PC with GPU, please check CUDA enabled GPU cards before buying one. I suggest you buy a PC with Nvidia graphic card having at least 12GB GDDR6 or GDDR6X. If you just got a new PC with Nvidia GPU, you go to Nvidia driver download and download the graphic card driver. After download, you run exe file to install.

2. Install Visual Studio Community 2019
Note: if you already have installed Nvida CUDA toolkit and library, you can skip next three steps.
In order to compile and support Nvidia toolkit and library, you need C++ compiler. You go to Visual Studio old downloads to get 2019. After you sign in, select community 2019 and download.

When you run installer, select “code editor” at the right side of the window. Click “continue” and finish the installation.
3. Install CUDA Toolkit 11.8.0
CUDA is a software layer that gives direct access to the Nvidia GPU’s virtual instruction set and parallel computational elements. According to Pytorch install guide, you need CUDA 11.8. Go to CUDA Toolkit archive at Nivdia, and select CUDA ToolKet 11.8.0. In the next window, select Windows, version of your operation system and installer type, you can download and follow default to install it.

It is installed at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8.
4. Install cuDNN 8.6
The Nvidia CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. Go to Nvidia’s cuDNN Archive, download cuDNN v8.6 (not the latest).

Extract the downloaded zip file and copy three sub folders, i.e. include, lib and bin.

Paste them to CUDA install folder at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\. New files are added to CUDA.

Open Environment Variables window, add following new two paths:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp

5. Install Anaconda3
Conda is an open-source package and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and their dependencies. To install, go to Anaconda site to download Anaconda installer, click the download button at top or go to bottom to select particular version for your PC.

After you run the installer, Anaconda3 is installed at C:\Users\yourusername\anaconda3. It also installs Python 3.10 there. Remember to add the following paths in “Environment Variables”:
C:\Users\yourusername\anaconda3
C:\Users\yourusername\anaconda3\Library\bin
C:\Users\yourusername\anaconda3\Scripts

In window start, you can find Anaconda3 folder. If you cannot find, search for “Anaconda prompt” in window search bar at the bottom. Create a shortcut of Anaconda prompt on your desktop. You will use it a lot.

Run Anaconda prompt, a prompt window opens. It shows (base) C:\Users\yourusername>. (base) represents your current environment. “base” is a default env.

You can run conda or pip commands to see what packages have been installed.
$conda list
$pip list
6. Create virtual environment for TyPorch
A virtual environments is an isolated environment for Python projects. Each project can have its own dependencies, regardless of what dependencies every other project has.
To run PyTorch, it is a good idea to create its own virtual environment. Open Andaconda prompt window, enter commands:
$conda create –name pytorch_env python=3.10
$conda activate pytorch_env

Now you are in “pytorch_env” virtual env.
7. Install PyTorch 2.0
Go to PyTorch site to check the software compatibilities, as orange highlights in the following chart.

Copy the command at the bottom and run in your Anaconda prompt. This command installs PyTorch and other common used packages such as numPy.
$pip3 install torch torchvision torchaudio –index-url https://download.pytorch.org/whl/cu118
To check whether Pytorch installed correctly with GPU support, run python in Anaconda prompt.
$python
Then run
>>>import torch
>>>torch.cuda.get.device_name(0)
If it returns your GPU card name, you have successfully installed PyTorch with GPU support.

8. Run your project
You can run python code in Andaconda prompt window. For example enter commands:
$python app.py
Sometimes, you need to install additional packages or modules. You can run pip or conda in Anaconda prompt. For example,
$pip install ipython
$conda install -c conda-forge ffmpeg
9. Install PyCharm
PyCharm is an integrated development environment used for programming in Python. If you want to edit and run your project in PyCharm, you need to install it first. Go to Download PyCharm at jebrains site. Download the Community version and run the installer.
After installation, open PyCharm and create a new project. In Python interpreter, check “Previously configured interpreter”. In the drop down, select “pytorch_env” you just created.
You can also change the interpreter for existing projects. Go to file->settings->project. In Python Interpreter, check “Using existing environment”, click “Add interpreter”, select “pytorch_env”.
