Register Login

Install PyTorch on Windows?

Updated Feb 15, 2024

Meta Description:

Install PyTorch on Windows using two Package Management Systems, i.e., pip and Anaconda, for Deep Learning modeling

PyTorch is an optimized and open-source Python framework for deep learning models. Based on the Torch library, this Machine Learning framework supports more than two hundred different mathematical operations. Its notable use cases are in scientific research and artificial intelligence (AI) applications.

Machine Learning and Deep Learning can power AI-driven tools. It brings the PyTorch framework to the table for data scientists. Let us dig deeper into the installation process of PyTorch on Windows through this one-stop guide.

Installation of PyTorch on Windows

Using the two Package Management Systems, i.e., pip and Anaconda, we will dive into installing the PyTorch on Windows. But for both these processes, users should first install Python on their system.

Installation 1: Install PyTorch using the pip package manager

Step 1: Ensure that the system has Python installed using the given command on Command Prompt:

python --version

The version will confirm that the system has Python installed.

Step 2: Then, check whether the system has pip installed using the following command:

pip --version

It will again check the version of the pip for confirmation.

Step 3: Use the pip command to install the PyTorch using:

pip3 install torch torchvision torchaudio

Also, users can use any of the following commands according to system specifications to install the latest version of PyTorch:

It is for CUDA 10.2 with Nvidia Driver version >= 441.22:

pip3 install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

It is for CUDA 11.1 with Nvidia Driver version >= 456.38:

pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

It is for CPU:

pip3 install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

Important: Often, users face installation problems where the CMD throws an exceptional error like –

In this case, users need to either uninstall and reinstall pip or upgrade the pip version using this command:

python.exe -m pip install --upgrade pip

Step 4: Users can also confirm the installation using the following command:

pip3 show torch

It is an additional installation step, ensuring a successful installation of the PyTorch framework.

Note: In case if users want to uninstall their outdated PyTorch version or the framework itself, then they can use this command:

pip uninstall torch

Installation 2: Using the Anaconda Package Manager:

Anaconda is a Command-line interface that comes with Anaconda distribution. It is the same as the Windows Command Prompt but runs on Windows PowerShell. So, let us dive into the installation process of PyTorch using the Anaconda package manager on Windows:

Step 1: First, check whether the system has Anaconda installed. If installed, check the version using this command:

conda -V

Hence, our Anaconda version is 4.14.0

Step 2: Open the Anaconda Package Manager in Administrator mode and run this command:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

or

conda install pytorch –c pytorch

Also, users can use any of the following commands according to system specifications to install the latest version of PyTorch –

It is for CUDA 10.2 with Nvidia Driver version >= 441.22:

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

It is for CUDA 11.1 with Nvidia Driver version >= 456.38:

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

It is for CPU:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

Step 3: The last step is to confirm or check whether the system has successfully installed PyTorch. Using this command, users can check the version of the framework they installed on their Windows:

conda list -f PyTorch

Conclusion

As we can see, installing PyTorch in Windows is very simple and fast, as illustrated in the above procedures (steps). This comprehensive guide gave you a walkthrough of the PyTorch framework and how to install it. You can install this framework on other operating systems like macOS and Linux.


×