Problem

The installation of this two packages is not as straight forward as it may look. If you have already use PyTorch framework in your computer, you may be familiar with the process of installation:

pip3 install torch; pip3 install torchvision

If you install the packages using those commands, you will have success, but PyTorch will not recognize that cuda is available

import torch
torch.cuda.is_available() # This will return False

If you install packages using requirements files, you have to open them and remove both torch and torchvision, to avoid that pip installs these packages in the wrong way.

How to install PyTorch

PyTorch, although we can’t install through pip, it’s relatively easy to install. All we have to do is to follow the steps in NVIDIA documentation. Here I made a shorter step-by-step with some tricks:

sudo apt-get -y update; 
sudo apt-get -y install autoconf bc build-essential g++-8 gcc-8 clang-8 lld-8 gettext-base gfortran-8 iputils-ping libbz2-dev libc++-dev libcgal-dev libffi-dev libfreetype6-dev libhdf5-dev libjpeg-dev liblzma-dev libncurses5-dev libncursesw5-dev libpng-dev libreadline-dev libssl-dev libsqlite3-dev libxml2-dev libxslt-dev locales moreutils openssl python-openssl rsync scons python3-pip libopenblas-dev;
export TORCH_INSTALL=**LinkFromPreviousStep**
python3 -m pip install --no-cache $TORCH_INSTALL

Test

Open python (if you installed as administrator, now only works as administrator)

python3

Then run

import torch
torch.cuda.is_available()

If return true, the installation was successful.

Exit python with ctrl+z

Uninstall

To uninstall just use

pip3 uninstall torch

Or, if the installation was done as administrator

sudo pip3 uninstall torch