
View the version of CUDA in WSL

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

Directly installing will result in an error. It is necessary to first install the virtual environment to prevent any impact on the system’s Python
The latest version no longer requires the use of Anaconda!
1 AnacondaIntroduction
Anaconda, Chinese python is an open-source Python distribution that includes over 180 scientific packages and their dependencies, such as conda and Python. Among them, conda is an open-source package and environment manager that can be used to install different versions of software packages and their dependencies on the same machine, and can switch between different environments.
1. Anaconda is extremely user-friendly for beginners of Python. Compared to installing the main Python program separately, choosing Anaconda can help save a lot of trouble. Anaconda adds many commonly used feature packages, which need to be installed one by one if Python is installed separately. In Anaconda, these feature packages do not need to be considered. At the same time, Anaconda also comes bundled with two very useful interactive code editors (Spyder, Jupyter Notebook).
2、 If we don’t install Anaconda, we will have to use pip install xxx to install third-party libraries. When we install too many libraries, it will cause file disorder and complexity problems. Moreover, the pip install method will default to installing the library in the same path. If someone else uses a lower version library for your program while you install a higher version library through pip, due to compatibility issues, your library cannot run the program, and you cannot delete your higher version library to download a lower version library that is compatible with the environment, so this is extremely cumbersome and inconvenient.
At this point, Anaconda’s effect comes out!!! It can create a virtual environment that is separate from your main environment, just like a dormitory building. A large dormitory building consists of many dormitory rooms, each inhabited by people, but they are all independent and separate, without affecting each other. If you don’t want to stay, you can check out at any time. That is to say, if you no longer want the virtual environment you create and it takes up memory, you can move and delete it at any time. So how to create a virtual environment through Anaconda? It’s the conda method!!!
Using conda to install PyTorch is a great choice, especially when you want to manage different Python environments or need to install libraries with specific dependencies. Conda can not only manage Python packages, but also handle all dependencies related to the environment, and is easier to solve compatibility issues than pip.
Install PyTorch using conda
Ensure that you have installed Anaconda or Miniconda:- Anaconda is a large Python distribution that includes numerous scientific computing libraries.
What is Anaconda? Anaconda is an open-source Python platform designed specifically for data science and machine learning developers, integrating the most commonly used data analysis tools with; Library. It has a rich built-in data science suite, including core tools such as Numpy (numerical operations), Pandas (data processing), and Seaborn (data visualization), allowing users to start working immediately without the tedious installation process. The installation and download steps of Anaconda are very simple, just download the executable file to complete the setup, and it fully supports major operating systems such as Windows, macOS, and Linux, allowing users to have a consistent development experience on different platforms. Through the built-in Conda environment management tool, users can easily create and switch between different development environments, effectively solving the problem of package version conflicts.

Download the corresponding installation package

sh Anaconda3-2025.06-0-Linux-x86_64.sh
Enter ‘yes’ and press enter to install

Checking the conda version, you can see that it has been successfully installed

Conda info View specific information

Add the conda environment variable in~/. bashrc for easy use

Embarrassed, I found that the latest PyTorch is no longer recommended for installation using Conda. Please refer to the Reddit and GitHub links at the end for details
sudo apt install python3-venv

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
During installation, some packages were found to download too slowly. You can manually download and install them



This completes the installation.
Create pytorch test. py and add the following content.
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()))
After running, determine the installation information based on the output.

Reference link
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://github.com/pytorch/pytorch/issues/138506
Published on July 13, 2025
