PyTorch Python

How to install PyTorch 1.5 (conda & pip)

Here you will learn how to install PyTorch 1.5 (both 1.5.0 and 1.5.1) through conda (Anaconda/Miniconda) and pip. PyTorch is a common Platform for Deep Learning. A number of open source code or papers already use 1.5 and authors are likely never going to upgrade. Typically, however, PyTorch installation guides install the newest version by default. You may already have tried the newest version, but it doesn’t work somehow and you’ll have to install PyTorch 1.5. How can I resolve it?


This tutorial assumes you can run python and a package manager like pip or conda. Miniconda and Anaconda are both good, but miniconda is lightweight. We wrote an article about how to install Miniconda.

4 Steps to Install PyTorch 1.5

  1. [Optional] Check if CUDA is installed

    It is highly recommended that you have CUDA installed. Note that PyTorch 1.5.0/1.5.1 does not support CUDA 11.0. If you have n't installed CUDA, click here to install CUDA 10.2.

    Once/If you have it installed, you can check its version here.

  2. [For conda on Ubuntu/Linux and Windows 10]
    Run conda install and specify PyTorch version 1.5.1

    Starting from here, we will install PyTorch 1.5.1. If you need to install 1.5.0, use “1.5.0” for pytorch and “0.6.0” for torchvision.

    CUDA 10.2: conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2 -c pytorch
    CUDA 10.1: conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1 -c pytorch
    CUDA 10.0: conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.0 -c pytorch
    CUDA 9.2: conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=9.2 -c pytorch
    CPU Only (your PyTorch code will run slower):
    conda install pytorch==1.5.1 torchvision==0.6.1 cpuonly -c pytorch

  3. [For conda on macOS]
    Run conda install and specify PyTorch version 1.5.1

    There is only one command to install PyTorch 1.5.1 on macOS:
    conda install pytorch==1.5.1 torchvision==0.6.1 -c pytorch

  4. [For pip] Run pip3 install by specifying version with -f

    CUDA 10.2: pip install torch==1.5.1 torchvision==0.6.1
    CUDA 10.1: pip3 install torch==1.5.1 torchvision==0.6.1 -f
    CUDA 10.0 is not officially supported by PyTorch 1.5, you have to install CUDA 10.2 or CUDA 10.1.
    CUDA 9.2: pip3 install torch==1.5.1 torchvision==0.6.1 -f
    PyTorch 1.5 also doesn't support CUDA 9.1 or 9.0.
    CPU only (GPU is much better…): pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f

  5. [For pip on macOS] Run pip3 install by specifying version with -f

    pip install torch==1.5.1 torchvision==0.6.1

  6. Verify PyTorch 1.5.1 is installed

    RunΒ Python/Python3Β with

    import torch

    This should either output 1.5.1 or 1.5.0 based on your installation.

  7. Verify PyTorch 1.5.1 is using CUDA

    import torch

Verify if PyTorch 1.5 is installed

We will verify the installation by running a sample PyTorch script to ensure correct installation of PyTorch 1.5. We will construct a tensor here, which is initialized at random.

import torch
print(torch.rand(3, 5))

The output are shown below. Yours will be similar.

tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])

Check if CUDA is available to PyTorch 1.5

To verify that PyTorch 1.5 is available and accessible for your GPU and CUDA driver, execute the following Python code to determine if the CUDA driver is enabled:

import torch

In case of people interested, PyTorch v1 and CUDA are introduced in the following 2 sections.

What is PyTorch?

PyTorch is an open-source Deep Learning platform that is scalable and versatile for testing, reliable and supportive for deployment. It allows for quick, modular experimentation via an autograding component designed for fast and python-like execution. With the introduction of PyTorch 1.0, the platform now has graph-based execution, a hybrid front-end that allows for smooth mode switching, collaborative testing, and effective and secure deployment on mobile platforms.

PyTorch has 4 key features according to its official homepage.

  1. PyTorch is production-ready: TorchScript smoothly toggles between eager and graph modes. TorchServe speeds up the production process.
  2. PyTorch support distributed training: The torch.collaborative interface allows for efficient distributed training and performance optimization in research and development.
  3. PyTorch has a robust ecosystem: It has an expansive ecosystem of tools and libraries to support applications such as computer vision and NLP.
  4. PyTorch has native cloud support: It is well recognized for its zero-friction development and fast scaling on key cloud providers.


By VarHowto Editor

Welcome to VarHowto!