Category

How to Install Pytorch on Windows, Macos, and Linux?

2 minutes read

PyTorch is a popular open-source machine learning library widely used for building deep learning models. Whether you are operating on Windows, macOS, or Linux, installing PyTorch is a straightforward process. This guide will walk you through the installation process on each platform, ensuring you have PyTorch ready for your next project.

Installing PyTorch on Windows

To install PyTorch on Windows, follow these steps:

  1. Verify System Requirements: Ensure that your system meets the minimum requirements. You should have Python 3.6 or later installed on your machine.

  2. Install Anaconda: If you haven’t already, download and install Anaconda, a package manager that simplifies managing Python dependencies.

  3. Create a Virtual Environment:

    1
    2
    
    conda create --name my_pytorch_env python=3.8
    conda activate my_pytorch_env
    
  4. Install PyTorch: Visit the PyTorch installation page and choose your preferences for PyTorch build, your operating system, package manager, and CUDA version. Then, execute the command provided. An example command might look like:

    1
    
    conda install pytorch torchvision torchaudio cpuonly -c pytorch
    
  5. Verify Installation:

    1
    
    python -c "import torch; print(torch.__version__)"
    

Installing PyTorch on macOS

To install PyTorch on macOS, you can use either Anaconda or pip. Below are instructions using Anaconda:

  1. Install Anaconda: If not installed yet, download and install Anaconda.

  2. Set Up a Virtual Environment:

    1
    2
    
    conda create --name my_pytorch_env python=3.8
    conda activate my_pytorch_env
    
  3. Install PyTorch: Go to the PyTorch installation page, select your options, and execute the command. A sample command might be:

    1
    
    conda install pytorch torchvision torchaudio -c pytorch
    
  4. Confirm Installation:

    1
    
    python -c "import torch; print(torch.__version__)"
    

Installing PyTorch on Linux

Installing PyTorch on Linux is similar to other platforms, particularly using Anaconda:

  1. Install Anaconda: Download and install Anaconda.

  2. Create a Virtual Environment:

    1
    2
    
    conda create --name my_pytorch_env python=3.8
    conda activate my_pytorch_env
    
  3. Install PyTorch: Navigate to the PyTorch installation page and follow the instructions to generate the correct command. It might look like:

    1
    
    conda install pytorch torchvision torchaudio -c pytorch
    
  4. Test the Installation:

    1
    
    python -c "import torch; print(torch.__version__)"
    

Additional Resources

By following this guide, you can easily install PyTorch on any of the three major operating systems and take advantage of its powerful features for your machine learning projects.