Installing PyTorch 2.0.0 on Windows 10/11

PyTorch is a neural network code library. By far the biggest hurdle for beginners is installation.

Note: These instructions also work for other PyTorch versions such as 1.13.1 and 2.1.0 and 2.2.1 — just different .whl files (see below). These instructions are for a CPU-only install (no GPU), but, again, you can just use a different .whl file for GPU, but GPU installs are much trickier than CPU installs.

Note: PyTorch 2.0 was released on March 15, 2023 and it is a significant change from all previous versions. Sadly, the two most important features of version 2.0 are still in Beta for PyTorch 2.0.0 — the compile() functionality and a new Transformer implementation. By the time you read this, a newer version of PyTorch such as 2.2.0 may be available. These instructions can be used — different .whl file.

Prerequisites: A machine with a relatively modern CPU (no older than 6 years old) running Windows 10 or 11, with Python 3.9.13 installed via the Anaconda 2022.10 distribution. See xhttps://jamesmccaffreyblog.com/2024/03/19/installing-anaco…on-windows-10-11/installing-anaconda3-2022-10-with-python-3-9-13-on-windows-10-11.

You must be logged on as a user with full administrative privileges and be connected to the Internet. You can check if you have admin privileges by launching a command shell (cmd) and typing the command “net user”. This will show you your current user name. Then type the command “net user name” and look for the Local Group Memberships entry – it should read “Administrators”.


1. You install PyTorch using a special .whl file and a program called pip (pip has been installed by Anaconda).

Prepare by creating a new directory called PyTorch, preferably in your root C:\ or D:\ directory. In the PyTorch directory, create a new sub-directory named Wheels to hold the .whl install file.


2. You must find the .whl installation file for PyTorch 2.0.0 CPU on Python 3.9.13 for Windows.

Do an Internet search for “pytorch 2.0 cpu windows”. You may need to search a bit. As I write this post, the .whl files were found at:

https://download.pytorch.org/whl/cpu/torch_stable.html

When you find the page, look for file:

torch-2.0.0%2Bcpu-cp39-cp39m-win_amd64.whl

Be very, very careful to get the one and only one correct .whl file — there are at least a dozen different versions of PyTorch 2.0, and the Web page has over 3,500 .whl files! You do not want to get the GPU version. By far most installation failures happen at this step when you get the .whl file.

Right-click and download the .whl file to your local machine. Save it directly into the Wheels directory you just created, or download the file to your Downloads directory and then move it to the Wheels directory.


3. Launch a command shell. Note: depending on your system configuration, you may need to launch the shell with “Run as Administrator” admin privileges. Navigate to the directory where you saved the .whl file. Enter the command:

pip install "torch-2.0.0+cpu-cp39-cp39m-win_amd64.whl"

Installation of PyTorch is relatively quick. The shell will display a message indicating successful installation. To verify PyTorch has been installed correctly, enter the following three commands (note: there are two consecutive underscores in the version command).

python
import torch as T
T.__version__

If you succeeded, congratulations! You can only learn PyTorch by running and experimenting with programs; now you’re ready.

Note: To uninstall just PyTorch but nothing else, launch a command shell and enter “pip uninstall torch”. You’ll get asked for confirmation.

To uninstall everything (Python, PyTorch, Keras if you have it, etc.), go to the Windows Control panel | Programs and Features | Uninstall and then uninstall Python-Anaconda. Make sure you know what you’re doing.

Note: Many PyTorch examples on the Internet work with image data, such as the MNIST hand-written digits dataset. To work with images you’ll eventually need the “torchvision” code library add-on. If you’re a beginner, I do not recommend installing torchvision. You can find a .whl file for torchvision on the same Web page as the PyTorch .whl file. For example:

torchvision-0.8.0%2Bcpu-cp37-cp37m-win_amd64.whl

You can right-click on the .whl file and download it to your local machine, and then install with a command such as:

pip install “torchvision-0.8.0%2Bcpu-cp37-cp37m-win_amd64.whl”

There is also a “torchtext” code library for natural language processing (NLP). NLP programs are significantly more complex than other types of problems so I don’t recommend torchtext for beginners. Version incompatibilities between torch, torchvision, torchtext, and their thousands of dependencies is a huge headache when working in the Python ecosystem.


This entry was posted in PyTorch. Bookmark the permalink.