Chapter 2: Guide to Installing PyTorch

by digitaltech2.com
PyTorch - Part 2

Installing PyTorch

Installing PyTorch is the first step to getting started with your deep learning projects. The installation process is straightforward and can be done in multiple ways, depending on your operating system and preference.

Installation via pip

PyTorch can be installed using pip, the Python package installer. Here’s how you can install it:

  1. Check Python Version: Ensure you have Python 3.6 or newer installed.
  2. Install via pip:
pip install torch torchvision torchaudio
Installation via Conda

Conda is a package manager that can simplify the installation of dependencies and libraries. Here’s how you can install PyTorch using Conda:

Install Conda: If you don’t have Conda installed, download and install it from the Anaconda website.

Create a Conda Environment:

conda create -n pytorch_env python=3.8
conda activate pytorch_env

Install PyTorch

conda install pytorch torchvision torchaudio cpuonly -c pytorch
Verification

To verify your installation, open a Python shell and run the following commands:

import torch
print(torch.__version__)
print(torch.cuda.is_available())

This should print the PyTorch version and indicate whether CUDA (GPU support) is available.

Related Posts