How to install PyTorch on Linux?

2023-10-25

AI is a hot topic in recent days and I decided to try to learn it for satisfying my curiosity. I did some research and dived into the python environment configuration.

  • install anaconda: sudo pacman -Sy anaconda
Please run
    $ source /opt/anaconda/bin/activate root
    $ source /opt/anaconda/bin/deactivate root
to activate and deactivate the anaconda enviroment.
  • source /opt/anaconda/bin/activate root

  • create isolated environment: conda create -n pytorch python=3.11

# To activate this environment, use
#
#     $ conda activate pytorch
#
# To deactivate an active environment, use
#
#     $ conda deactivate
  • activate environment: conda activate pytorch

  • show available cmds: pip list

  • if you have a nvidia GPU, you should check cuda version: nvidia-smi

  • download pytorch: follow the https://pytorch.org/ install steps

  • check cuda is available or not, enter python shell mode and run:

import torch
torch.cuda.is_available()

Enjoy your journey of learning AI.


Reference