PyTorch installation depends on your operating system and whether you want to use your GPU

PyTorch is a machine learning library that runs on Windows, Mac, and Linux. The installation process takes about 5 to 10 minutes and involves downloading a command from the official PyTorch website, then running it in your terminal or command prompt. The exact command you need changes based on three things: your operating system, your Python version, and whether you want to use your graphics card (GPU) to speed up calculations.

If you do not have Python installed yet, you will need to install that first — PyTorch requires Python 3.8 or newer. Once Python is ready, the PyTorch installation itself is a single command that downloads and sets up the library and its dependencies.

Key Takeaways

  • You must have Python 3.8 or newer installed before you can install PyTorch; check your Python version by typing python --version in your terminal.
  • Visit pytorch.org, select your operating system, Python version, and compute platform (CPU or GPU), and copy the command it generates for you.
  • Paste the command into your terminal or command prompt and let it run without interruption — this usually takes 2 to 5 minutes depending on your internet speed.
  • After installation finishes, test it by opening Python and typing import torch to confirm PyTorch loaded without errors.

Check your Python version before you start

Open your terminal (Mac or Linux) or command prompt (Windows) and type this command:

python --version

Press Enter. You should see something like "Python 3.11.5" or "Python 3.9.2". If you see Python 2 or a version older than 3.8, you need to install a newer version of Python first. If the command does not work at all, Python is not installed on your system yet.

On Windows, if python does not work, try py --version instead. If neither works, download Python from python.org, run the installer, and make sure you check the box that says "Add Python to PATH" during setup.

Go to pytorch.org and generate your installation command

Open your web browser and go to pytorch.org. You will see a section near the top of the page with dropdown menus. Select your setup in this order:

  1. Operating System: Choose Windows, Mac, or Linux.
  2. Package: Leave this set to "Pip" unless you use Conda (most people use Pip).
  3. Language: Choose Python.
  4. Compute Platform: Choose CPU if you do not have an NVIDIA graphics card, or GPU if you do. If you are not sure, choose CPU — it will work on any computer.

After you make these selections, a command will appear in a gray box below the menus. It will look something like pip install torch torchvision torchaudio or longer depending on your choices. Copy this entire command — click the copy button next to it or select all the text and copy it manually.

Run the installation command in your terminal

Go back to your terminal or command prompt window and paste the command you copied. Press Enter and let it run. You will see text scrolling as PyTorch and its dependencies download and install. This usually takes 2 to 5 minutes depending on your internet speed and how much your computer has to download.

Do not close the terminal or interrupt the process. If your internet drops or the process stops with an error, you can run the same command again — it will pick up where it left off.

When the installation finishes, you will see a line that says something like "Successfully installed torch" and your terminal prompt will return. If you see an error message instead, read the error carefully — common problems include not having enough disk space, a network interruption, or a Python version mismatch.

Test your installation to make sure it worked

Type python into your terminal and press Enter. This opens the Python interactive shell. You should see a prompt that looks like >>>.

Now type this command:

import torch

Press Enter. If nothing happens and you see the >>> prompt again, PyTorch installed correctly. If you see an error message like "ModuleNotFoundError: No module named 'torch'", the installation did not work — go back and check that you ran the correct command for your system.

You can also check the PyTorch version by typing print(torch.__version__) and pressing Enter. This will show you which version you installed. Type exit() to leave the Python shell and return to your terminal.

Troubleshooting common installation problems

If you see "command not found" or "is not recognized as an internal or external command", the pip tool is not in your system path. On Windows, try using py -m pip install instead of pip install. On Mac or Linux, try python3 -m pip install instead of pip install, then paste the rest of the command from pytorch.org.

If the installation starts but then fails partway through, check that you have at least 5 GB of free disk space. You can also try running the command again — sometimes network hiccups cause partial failures that succeed on a second attempt.

If you chose GPU but your graphics card is not being recognized, you may need to install NVIDIA drivers separately. PyTorch can still run on CPU even if your GPU is not set up, so you can use CPU mode while you troubleshoot the GPU setup.

Using PyTorch after installation

Once PyTorch is installed, you can use it in any Python script or Jupyter notebook. Start your script with import torch at the top, and you can then use PyTorch functions and classes.

If you are new to PyTorch, the official tutorials at pytorch.org/tutorials show you how to build and train models. Most people start with the "Introduction to PyTorch" tutorial, which walks through the basics with real code examples you can run on your own computer.

Frequently Asked Questions

Do I need a graphics card to use PyTorch?

No. PyTorch runs on CPU (your regular processor) on any computer. A graphics card speeds up training for large models, but CPU mode works fine for learning, small projects, and inference. Choose CPU during installation if you do not have an NVIDIA card.

What is the difference between Pip and Conda?

Both are package managers that download and install Python libraries. Pip is simpler and comes with Python by default. Conda is part of Anaconda and handles dependencies more carefully. For most people, Pip is the right choice. If you already use Anaconda, you can choose Conda from the pytorch.org dropdown instead.

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

Yes. Select Mac as your operating system and CPU as your compute platform on pytorch.org. PyTorch runs natively on Apple Silicon (M1, M2, M3) without any extra steps, though GPU acceleration on Apple Silicon is still experimental.

What if I want to uninstall PyTorch later?

Type pip uninstall torch in your terminal and press Enter. You can also uninstall related packages like pip uninstall torchvision torchaudio if you installed those too. This removes PyTorch but leaves Python intact.

Can I install multiple versions of PyTorch on the same computer?

Not easily in the same Python environment. If you need different versions, create separate Python virtual environments — one for each version. This keeps them from conflicting. Search for "Python virtual environment" to learn how to set one up.