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.
- macOS
- Linux
- Windows
pip install torch==1.12.1
pip install torch==1.12.1+cpu
pip install torch==1.12.1+cpu
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