Skip to content
Related Articles

Related Articles

Install Pytorch on Linux

View Discussion
Improve Article
Save Article
  • Last Updated : 09 Jun, 2022

In this article, we are going to see how you can install PyTorch in the Linux system. We are using Ubuntu 20 LTS you can use any other one. To successfully install PyTorch in your Linux system, follow the below procedure:

First, check if you are using python’s latest version or not.

Because PyGame requires python 3.7 or a higher version, make sure you are using the latest version of python. Type the below command to check the version of python.

python3 –version

Note: If Python is not installed, refer to install python in Linux.

Check if you are using the latest version of pip or not:

The pip is a python package installer, if you want to use any external package in your python file you first install it in your local system using pip. Run the following command to check the version of pip. 

pip3 –version

If you are already using the new pip version so follow the below steps if not, so refer to the article on how to install pip in Linux.

Switch to root user and update Linux packages if you are not using the latest pip version:

Open the terminal and make sure you are the root user. Run the following command to switch to root user.

sudo su

Update Linux packages using the below command.

apt update

After this step, you are ready to install PyTorch on your Linux system.

Installing PyTorch

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

The above command was used to install PyTorch in the system that didn’t have GPU. You just copy the command and paste it into the terminal and run it.

The below command is used to install PyTorch on a system which has GPU. Make sure you have python 3.7 or higher.

pip3 install torch torchvision torchaudio

To make sure PyTorch is installed in your system, just type python3 in your terminal and run it. After that type import torch for use PyTorch library at last type and run print(torch.__version__) it shows which version of PyTorch was installed on your system if PyTorch was installed on your system.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!