Install wsl ubuntu and cuda-pytorch under win11

Table of contents

1. wsl ubuntu installation

1.1 Installation

1.2 Migration

2. Install cuda

2.1 Installation

2.2 Environment variable configuration 

2.3 Check installation

3 Install cudnn according to CUDA version

4 Install anaconda

5 Install pytorch

5.1 Create a virtual environment

5.2 Activate virtual environment

5.3 Install PyTorch

6 Check cuda usage


1. wsl ubuntu installation

1.1 Installation

wsl install

1.2 Migration

1. Open PowerShell and terminate the running distribution or virtual machine:
wsl --shutdown

2. Export the distribution or virtual machine that needs to be migrated (the version I installed is Ubuntu-20.04):
wsl --export Ubuntu-20.04 E:\wslubuntu

3. Query
wsl -l -v

4. Uninstall the distribution or virtual machine:
wsl --unregister ubuntu

5. Import the new distribution or virtual machine:
wsl --import ubuntu [new installation path] E:\wslubuntu\ubuntu-20.04.tar
For example: wsl --import ubuntu E:\wslubuntu E:\wslubuntu\ubuntu-20.04 .tar

6. Next you need to retrieve your account:
ubuntu config --default-user jane [user name]

7. The migration is successful.

2. Install cuda

Check whether windows supports cuda.

Enter the command under PowerShell: nvidia-smi

2.1 Installation

Installing CUDA in deb mode will install the graphics card driver, which is installed by default;

CUDA Toolkit 12.2 Downloads | NVIDIA Developer

The network installation selected here:

2.2 Environment variable configuration 

Next, configure the environment variables of wsl2 internal cuda:

#Open the .bashrc file here first
sudo nano /home/$USER/.bashrc
#Copy these three lines to the bottom of the file
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr /local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
#Update the bashrc file
source /home/$USER/.bashrc

#Update the dependencies you may need:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

2.3 Check installation

#Check whether cuda is installed successfully :
nvcc -V

3 Install cudnn according to CUDA version

 Find the corresponding cudnn according to the cuda version: cuDNN Archive | NVIDIA Developer

4 Install anaconda

Official website download link: https://www.anaconda.com/Tsinghua
University open source software mirror station: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

Select Anaconda3-2023.07-1-Linux-x86_64.sh

 Enter the command: sh Anaconda3-5.2.0-Linux-x86_64.sh

After the installation is complete, set the environment variables: vim .bashrc

 Execute source activate

5 Install pytorch

5.1 Create a virtual environment

1. Open wsl, activate anaconda, and enter the following command:

conda create -n pytorch python=3.10
creates a virtual environment named pytorch through conda. 3.9 is the python version. You can change it according to your own needs. Be sure to specify the specific python version.

2. After the creation is successful, enter the following command to view all installed environments:

conda info --envs

5.2 Activate virtual environment

Enter the following command:

conda activate pytorch

5.3 Install PyTorch

1. Open the pytorch official website: https://pytorch.org/ and click Get Started

2. According to the prompts on the official website, select the appropriate CUDA version and copy the command in the command

3. Open wsl, enter the pytorch environment just created, and enter the command copied before

6 Check cuda usage

Output cuda detection information

Guess you like

Origin blog.csdn.net/u010192735/article/details/131942367