PyTorch Installation in Easy Steps
Free Machine Learning courses with 130+ real-time projects Start Now!!
PyTorch is a machine learning and deep learning framework that provides easy and efficient tools to tackle various complicated tasks. It can easily be downloaded from the official PyTorch website using conda or pip package managers.
Requirements for PyTorch Installation
Before installing PyTorch there are some requirements that need to be fulfilled to be able to download and use PyTorch.
a. Supported Operating Systems:
PyTorch is supported on Windows 7 or above, MacOS 10.10 or above and for Linux users Arch Linux (2012-07-15 or higher) , CentOS(7.3-1611 or above), Debian (8.0 or higher), Fedora (24 or higher), Mint (14 or higher), OpenSUSE (42.1 or higher), PCLinuxOS (2014.7 or higher), Slackware (14.2 or higher), Ubuntu (13.04 or higher) support PyTorch.
b. Python:
Python is pre-installed on Linux and there is no need to install any additional file. To install Python on Windows or MacOS, go to the official Python website and download the latest version of Python and run the downloaded file to complete the process.
Note: If you do not want the latest version of Python you should download Python 3.6 or above as PyTorch is not supported by older versions.
c. Package Manager:
Either pip or conda is required for installing PyTorch. pip gets installed along with python and we are good to go. To install conda, go to the official Anaconda website and download the latest version in accordance with your Operating System. Though both pip and conda get the job done, conda is preferred as all the packages required to implement PyTorch are already installed along with Anaconda.
Note: There is no need to install Python if you have already installed Anaconda.
d. CUDA:(optional)
Computer Unified Device Architecture (CUDA) is an API (Application Programming Interface) and parallel computing platform that increases the speed of training our PyTorch models by 40-50%. However, this is an optional requirement and it’s absence will seldom be noticed.
Steps for PyTorch installation
1: Go to the PyTorch official website. Scroll to a table like the one shown below.
2: Select the version you want to download.
3: Select your operating system – Linux/Windows/MacOS
4: Now we have to select the package manager for our installation. Conda is generally preferred over other package managers as it is convenient to use especially for beginners. If your coding language is C++ then choose Libtorch. And if you want to develop your projects on PyTorch core itself then choose ‘Source’ which is neither required nor recommended for beginners.
5: Select Language- select python if you choose conda, pip or source in the previous step otherwise select C++/Java.
6: Now choose Compute platform, if you are windows or Linux user and have cuda installed in your system choose the appropriate version otherwise choose CPU. If you are a Mac user, cuda is not applicable, you can only choose CPU.
7: After you have chosen all the specifications you will see a command generated at the bottom of the table. Run this command on the terminal if you are a Linux or MacOS user. If you are a windows user run this command on the Anaconda prompt. In case you have chosen conda as your package manager and if you opted for pip then enter the command in ‘command prompt’.
8: Now the download will begin. Since the file being downloaded is quite hefty it will take some time to complete the download. While installing you may be asked yes/no at one or more instants. Reply y in all these cases.
Testing the PyTorch Environment Setup
Now that our package is installed, it is a good practice to test if it is working properly by running a few commands. Search ‘python’ in the search bar of your system and open ‘python shell’ or any other code editor. Now we will import and run a command or two.
import torch var=torch.zeros(5,9) print(var) tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Since our command is executed successfully and we get no error message we can be assured that PyTorch is installed and functioning properly.
Summary
Pytorch can be installed on any operating system from the official website in a few simple steps. The installation can be tested by importing the torch and running a few commands.
If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google
I am getting following error while trying to install pytorch following steps given here:
ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch
please suggest me the solution.