Skip to main content
Version: Next

Install PyTorch

In this tutorial, we will learn a quick way for how to set up PyTorch.

[OPTIONAL] Set up Python virtual environment

It is recommended to run the Python scripts in a virtual environment. Python offers a command to create a virtual environment with the following command.

python3 -m venv venv
source venv/bin/activate

Install torch dependency

Last, let's install the PyTorch dependencies via the Python package manager.

pip install torch==1.12.1

Test Installation

Open Python interpreter in terminal

python

Then execute the two lines of code, which will print the PyTorch version

import torch
print(torch.__version__)
Output
1.12.1

Exit the Python interpreter with exit().

That's it! PyTorch is installed successfully