Press "Enter" to skip to content

windows基于wsl2安装cuda运行环境

安装wsl2

https://learn.microsoft.com/en-us/windows/wsl/install

wsl --install

默认安装的就是 wsl2

安装完成之后重启系统,wsl会自动打开命令行进行ubuntu系统安装,安装完成后进入wsl命令行

安装cuda

# 更新系统
sudo apt update && sudo apt upgrade -y

# 安装 CUDA Toolkit(WSL 版本)
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt update
sudo apt install cuda-toolkit-12-4

# 设置环境变量
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

安装cuda的时候可能会报错:

nsight-systems-2023.4.4 : Depends: libtinfo5 but it is not installable

https://askubuntu.com/questions/1491254/installing-cuda-on-ubuntu-23-10-libt5info-not-installable

需要配置:

编辑文件:/etc/apt/sources.list.d/ubuntu.sources

文件末尾增加:

Types: deb
URIs: http://old-releases.ubuntu.com/ubuntu/
Suites: lunar
Components: universe
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

运行更新:

sudo apt update

再进行cuda的安装,就不会报错了。

安装Conda

https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html

下载安装包:https://repo.anaconda.com/archive/Anaconda3-2025.06-0-Linux-x86_64.sh

执行安装包

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

根据向导配置。

配置运行环境

source /root/.bashrc
conda create -n Monkey python=3.10
conda activate Monkey

export CUDA_VERSION=124 # for CUDA 12.4
# export CUDA_VERSION=121 # for CUDA 12.1

# Install PyTorch. Refer to https://pytorch.org/get-started/previous-versions/ for version compatibility
pip install --resume-retries 10 torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu${CUDA_VERSION}

pip install -e .

pip install lmdeploy==0.8.0
发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注