The installation of PyTorch is pretty straightforward and can be done on all major operating systems. However, if you want to get your hands dirty without actually installing it, Google Colab provides a good starting point.
Colab comes with preinstalled PyTorch and Tensorflow modules and works with both GPU and TPU support.
For installation on your own computer, PyTorch comes with both the CUDA and no CUDA versions, depending upon the hardware available to you.
This will be a single step installation – PyTorch Start Locally.
Prerequisite: Anaconda Distribution (Link to official website) – You need Anaconda installed on your system to follow this tutorial. The download packages are available for all major operating systems and the process of installation is very straight forward.
So before you go ahead with the tutorial, make sure you have an up and running Anaconda distribution set up on your operating system.
Note: In case you don’t want to use Anaconda, you can always use PIP to install PyTorch. Since PIP comes bundled with Python installer, you will already have it in your system.
Install Pytorch on Windows
The PyTorch website provides the following command for the windows system. PyTorch works with Windows 7 or higher and uses Python 3 or higher. Installing it using Anaconda is quite simple and can be done in a few minutes.
The next step is to paste the following command in your Anaconda prompt and run it.
1 |
conda install pytorch torchvision cpuonly -c pytorch |
The prompt will list out all the dependencies that will be installed along with PyTorch. If you are okay to proceed, type yes in the command line.
Anaconda now proceeds with the installation. You can check the installation through the Python interpreter or a Jupyter Notebook later.
Now you have successfully installed PyTorch on your Windows system.
Installing PyTorch on Linux
If you open the same installation page from a Linux machine, you will notice that the generated command will be a different one.
The next step is to copy and paste the command into your terminal and run it.
1 2 |
conda install pytorch torchvision cpuonly -c pytorch <img class="alignnone wp-image-29690 size-full" src="http://all-learning.com/wp-content/uploads/2020/02/pytorch-ubuntu-installation4.png" alt="pytorch-ubuntu-installation" width="1200" height="628" /> |
The terminal asks you for permission to install/update packages. You need to press yes as a response.
The installation will now continue to install torch and torchvision packages into your environment.
Installing PyTorch on Mac OS
We will use PIP to install PyTorch in Mac OS. All we need is to select the appropriate options on the PyTorch home page to get the install command.
So, we have to run the following command to install PyTorch and torchvision libraries on Mac OS.
1 |
$ pip3.7 install torch torchvision |
Here is the output from the Terminal when the above command is executed.
The last line of the output clearly states that both torch and torchvision packages are successfully installed.
Let’s launch the Python 3.7 interpreter and print the torch version to confirm the successful installation.
1 2 3 4 5 6 7 8 9 |
$ python3.7 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> print(torch.__version__) 1.4.0 >>> <img class="alignnone wp-image-29688 size-full" src="http://all-learning.com/wp-content/uploads/2020/02/PyTorch-Version1.png" alt="PyTorch-Version" width="1200" height="628" /> |
Conclusion
PyTorch is a very powerful machine learning framework. It’s used a lot in creating deep learning by processing large amounts of data. We will look into more features of PyTorch in the upcoming tutorials.