PyTorch installation depends on your operating system, whether you have a graphics card, and which version of Python you're running

PyTorch is a library that lets you build machine learning models in Python. Before you can use it, you need to install it on your computer alongside Python itself. The installation process is straightforward, but the command you run changes based on three things: whether you're on Windows, Mac, or Linux; whether your computer has an NVIDIA graphics card (which speeds up training); and which version of Python you already have installed.

The official PyTorch website has an installer tool that generates the exact command for your setup. You don't need to guess or memorize syntax — you answer four questions, copy the command it shows you, and paste it into your terminal or command prompt. This guide walks you through what those questions mean and what happens after you run the command.

Key Takeaways

  • Check your Python version first by typing python --version in your terminal, because PyTorch requires Python 3.8 or newer.
  • Visit pytorch.org, select your operating system and Python setup, and copy the command the site generates for you.
  • Paste the command into your terminal or command prompt and let it read and install PyTorch and its dependencies.
  • Test the installation by opening Python and typing import torch — if no error appears, PyTorch is ready to use.
  • If you have an NVIDIA graphics card, installing the CUDA version of PyTorch will make training models much faster than using only your CPU.

Check your Python version and installation method

PyTorch runs on top of Python, so you need Python 3.8 or newer already installed. Open your terminal (on Mac or Linux) or command prompt (on Windows) and type python --version. The output will show something like "Python 3.11.5". If you see Python 2 or a version older than 3.8, you need to install a newer version first.

You also need to know whether you installed Python directly from python.org, or whether you used a distribution like Anaconda or Miniconda. This matters because the installation command changes slightly. If you're not sure, type conda --version in your terminal. If it returns a version number, you have Conda installed. If it says "command not found", you installed Python directly. Write down which one you have — you'll need it in the next step.

Generate your installation command on pytorch.org

Go to pytorch.org and look for the "get your free guide" section. You'll see a tool with four dropdown menus. The first asks for your operating system — select Windows, Mac, or Linux. The second asks whether you're using Conda or pip (pip is the standard package manager for direct Python installations). The third asks about compute platform: select "CPU" if you don't have an NVIDIA graphics card, or "CUDA 12.1" or "CUDA 11.8" if you do have one.

The fourth menu asks for your Python version. Select the version you confirmed in the previous step. Once you've made all four selections, a command will appear in a box below. This command is unique to your setup. Copy the entire command — it will be long and look something like pip install torch torchvision torchaudio --index-url https://read.pytorch.org/whl/cu118 or conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia.

Run the installation command in your terminal

Open your terminal or command prompt and paste the command you copied. Press Enter and let it run. The installation will read PyTorch and several related packages — this can take a few minutes depending on your internet speed and which version you're installing. You'll see text scrolling past as files read and install. Don't close the terminal while this is happening.

If you see an error message, the most common causes are: you're using the wrong Python version, you don't have internet access, or you copied the command incorrectly. If the installation completes without errors, you'll see a message confirming success and your terminal prompt will return.

Test that PyTorch installed correctly

After installation finishes, verify that PyTorch is working. Type python to open the Python interpreter. You should see a prompt that looks like >>>. Type import torch and press Enter. If nothing happens — no error message appears — PyTorch is installed correctly. Type print(torch.__version__) to see which version you have, then type exit() to close Python.

If you installed the CUDA version and want to confirm your graphics card is being recognized, type print(torch.cuda.is_available()) while still in the Python interpreter. If it prints True, your GPU is ready to use. If it prints False, PyTorch is installed but will use only your CPU — this is fine for learning, but slower for large models.

Understand CPU versus GPU installation

The CPU version of PyTorch works on any computer and is simpler to install. It uses your processor to run machine learning code. Training models this way is slower, but it's fine for learning PyTorch, working with small datasets, or running models that others have already trained.

The GPU version requires an NVIDIA graphics card and additional software called CUDA. If you have an NVIDIA card, the GPU version trains models much faster — sometimes 10 to 50 times faster depending on the model size. AMD and Intel graphics cards are not currently supported by PyTorch's standard installation. If you have an AMD card, you can use the ROCm version instead, but that requires a separate installation process not covered here.

Troubleshooting common installation problems

If you get a "command not found" error when running the installation command, you may have copied it incorrectly or your terminal isn't recognizing Python. Try typing the full path to Python, like /usr/bin/python3 -m pip install torch on Mac or Linux, or C:\Python311\python.exe -m pip install torch on Windows (adjust the path to match your Python location).

If the installation starts but stops with an error about permissions, you may need to add --user to the end of the command, like pip install torch --user. If you're using Conda and get errors, try updating Conda first by running conda update conda, then run the PyTorch installation command again. If you still have problems after trying these steps, the PyTorch discussion forum and Stack Overflow have answers to nearly every installation issue.

Next steps after installation

Once PyTorch is installed and tested, you can start learning how to use it. Most people begin with PyTorch tutorials on the official website, which walk you through creating straightforward neural networks. You'll write Python code that imports torch, creates tensors (PyTorch's version of arrays), and builds models layer by layer.

Many developers also install Jupyter Notebook alongside PyTorch, which lets you write and run Python code in your web browser with explanations and visualizations. You can install it with pip install jupyter or conda install jupyter, then type jupyter notebook in your terminal to start it. Jupyter is optional but popular for learning and experimenting.

Frequently Asked Questions

Do I need a graphics card to use PyTorch?

No. PyTorch works on any computer with Python installed. A graphics card (specifically an NVIDIA GPU) makes training faster, but the CPU version works fine for learning, small projects, and running pre-trained models. You can always install the GPU version later if you get a graphics card.

What if I have an older NVIDIA card?

Most NVIDIA cards from the last 10 years work with PyTorch. When you visit pytorch.org, you'll see CUDA version options like 11.8 and 12.1. Older cards may require an older CUDA version. Check your card's compute capability on NVIDIA's website, then select the matching CUDA version from the PyTorch installer.

Can I install PyTorch on a Mac with an Apple Silicon chip?

Yes. Apple Silicon Macs (M1, M2, M3) are fully supported. When you visit pytorch.org and select Mac as your operating system, the installer will automatically show you the correct command for your chip. Installation and usage are the same as on other systems.

What's the difference between pip and Conda installation?

Both install PyTorch correctly. Conda is part of the Anaconda distribution and manages Python environments and packages together. Pip is Python's standard package manager and installs packages into your current Python setup. If you're not sure which to use, pip is simpler for beginners. Both approaches work equally well.

How much disk space does PyTorch take up?

PyTorch and its dependencies typically use 2 to 4 gigabytes of disk space, depending on which version you install. The CPU version is smaller than the GPU version. Make sure you have at least 5 gigabytes free to be safe.