PyTorch Installation on Windows, Linux, and MacOS

Filed Under: PyTorch
Installing PyTorch

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.

PyTorch Installation 1
PyTorch Installation 1

The next step is to paste the following command in your Anaconda prompt and run it.

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.

PyTorch Installation in Windows
PyTorch Installation 2

Anaconda now proceeds with the installation. You can check the installation through the Python interpreter or a Jupyter Notebook later.

PyTorch Version Check
PyTorch Version

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.

PyTorch Linux
PyTorch Linux

The next step is to copy and paste the command into your terminal and run it.

conda install pytorch torchvision cpuonly -c pytorch
Pytorch Ubuntu Installation
Pytorch Ubuntu Installation

The terminal asks you for permission to install/update packages. You need to press yes as a response.

Pytorch Ubuntu Packages
Pytorch Ubuntu Packages

The installation will now continue to install torch and torchvision packages into your environment.

Pytorch installation in Ubuntu Progress
Pytorch Ubuntu Progress

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.

Pytorch Quick Start Locally Mac Os
Pytorch Quick Start Locally Mac Os

So, we have to run the following command to install PyTorch and torchvision libraries on Mac OS.

$ pip3.7 install torch torchvision

Here is the output from the Terminal when the above command is executed.

Pip Install Torch
Pip Install Torch

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.

$ 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
>>>
Python Print Torch Version
Python Print Torch Version

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages