Check the CUDA version in WSL

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

Installing it directly throws an error. You need to set up a virtual environment first, so it doesn’t mess with the system Python

The latest version doesn’t need Anaconda anymore!

1 Anaconda Introduction

Anaconda, which means giant python in Chinese, is an open-source Python distribution that comes with conda, Python and over 180 scientific packages and their dependencies. conda is an open-source package and environment manager: it lets you install different versions of software packages and their dependencies on the same machine, and switch between environments.

2 Why install Anaconda?

1. Anaconda is super friendly to Python beginners. Compared with installing the main Python program on its own, going with Anaconda saves you a lot of hassle. Anaconda comes with plenty of commonly used packages, which you’d have to install one by one if you installed Python separately — in Anaconda you don’t have to think about it. It also bundles two really handy interactive code editors (Spyder, Jupyternotebook).

2. If we don’t install Anaconda, we have to install third-party libraries with pip install xxx. Once you’ve installed a bunch of libraries, files turn into a mess. On top of that, pip install drops everything into the same path by default. Say you start a project and the program someone else hands you is built on an older version of a library, while you installed the newer version through pip — because of that compatibility problem your library can’t run their program, and of course you’re not going to delete your newer library just to download the old one that fits. That’s way too tedious and annoying.

Now Anaconda steps in!!! It creates a virtual environment that’s separate from your main environment, kind of like a dorm building: one big building made of many rooms, each room with people living in it, but they’re all independent and don’t affect each other. If you don’t want to live there anymore, you can move out any time. Same thing — if you don’t want a virtual environment you created, or it’s taking up space, you can move it out and delete it whenever. So how do you create a virtual environment with Anaconda? The conda command!!!

Using conda to install PyTorch is a really good choice, especially when you want to manage different Python environments or need to install a library with specific dependencies. conda doesn’t just manage Python packages, it also handles everything else tied to the environment, and it’s easier to sort out compatibility problems than with pip.

Install PyTorch with conda

  1. Make sure you already have Anaconda or Miniconda installed:
    • Anaconda is a big Python distribution packed with scientific computing libraries.

What is Anaconda? Anaconda is an open-source Python platform made for data science and machine learning developers, integrating the most commonly used data analysis tools withfunction libraries. It ships with a rich set of data science packages, covering core tools like Numpy (numerical computing), Pandas (data processing) and Seaborn (data visualization), so you skip the tedious install steps and can start working right away.

Downloading and installing Anaconda is dead simple — just grab the installer and you’re set — and it fully supports the main operating systems, Windows, macOS and Linux, so the experience is the same on any platform. With the built-in Conda environment tool you can easily create and switch between development environments, which neatly solves package version conflicts.

Download the matching installer

sh Anaconda3-2025.06-0-Linux-x86_64.sh

Type yes and hit enter to install

Check the conda version — you can see it installed fine

conda info shows the details

Add the conda environment variables to ~/.bashrc so it’s convenient to use

Awkward — I got this far and then found out the latest PyTorch no longer recommends installing with conda. See the Reddit and GitHub links at the end for the details

sudo apt install python3-venv

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

During the install some packages downloaded way too slowly, so I grabbed them by hand and installed them manually

And that’s the install done.

Create pytorch_test.py and add the following.

import torch
print("PyTorch 版本:", torch.__version__)
print("是否支持 CUDA:", torch.cuda.is_available())
if torch.cuda.is_available():
    print("当前 CUDA 设备数量:", torch.cuda.device_count())
    print("当前使用的设备:", torch.cuda.current_device())
    print("设备名称:", torch.cuda.get_device_name(torch.cuda.current_device()))

Run it and read the output to see how the install went.

References

https://pytorch.org/get-started/locally

https://blog.csdn.net/liuhyusb/article/details/135753864

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D

https://www.reddit.com/r/Python/comments/1idsbj7/pytorch_deprecatea_official_anaconda_channel/?tl=zh-hans

https://github.com/pytorch/pytorch/issues/138506

Published on July 13, 2025

Leave a Reply

Your email address will not be published. Required fields are marked *