Running and building Pytorch on Google Colab
I am trying to run a python package that requires pytorch-gpu. I have change the runtime type of my Colab notebook to GPU. When I run the command, I am facing the following error. Not sure if I am able to build pytorch on colab myself? 

Traceback (most recent call last):
  File "inference_unet.py", line 9, in &lt;module&gt;
    import torchvision.transforms as transforms
  File "/usr/local/lib/python3.6/dist-packages/torchvision/__init__.py", line 10, in &lt;module&gt;
    from .extension import _HAS_OPS
  File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 58, in &lt;module&gt;
    _check_cuda_version()
  File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 54, in _check_cuda_version
    .format(t_major, t_minor, tv_major, tv_minor))
RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=10.2 and torchvision has CUDA Version=10.1. Please reinstall the torchvision that matches your PyTorch install.


Now you can directly use pytorch-gpu on google colab, no need of installation.
Just change your runtime to gpu, import torch and torchvision and you are done.
I have attached screenshot doing just the same.

Hope the answer will find helpful.



But in case you want to install different version of pytorch or any other package then you can install using pip, just add ! before your pip command and run the cell.

for example,

