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.
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.
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.
Update Linux packages using the below command.
After this step, you are ready to install PyTorch on your Linux system.
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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!