windows 11安装WSL和linux系统

3 阅读2分钟

检查并开启必要的 Windows 功能

  1. Win + R,输入 optionalfeatures 并回车。
  2. 确保勾选以下三项:
    1. 适用于 Linux 的 Windows 子系统 (WSL)
    2. 虚拟机平台 (Virtual Machine Platform)
    3. Hyper-V(如果你的版本支持)
  3. 点击确定后必须重启电脑。 如果上述软件层面操作均无效,请检查电脑重启时进入 BIOS,确保 Intel VT-x 或 AMD-V (Virtualization Technology) 已设置为 Enabled。

安装 WSL | Microsoft Learn

右键单击并选择“以 管理员 身份运行”,在管理员模式下打开 PowerShell,

  1. 查看可用发行版列表
wsl --list --online
  1. 安装发行版本
wsl --install -d <DistroName>

如果安装过程停在0.0%,可以先下载发行版

wsl --install --web-download -d <DistroName>
  1. 进入ubuntu
wsl -d ubuntu
wsl --shutdown # 关机
  1. 修改配置 win + R 输入%UserProfile%,编辑.wslconfig文件,如果没有则创建 写入配置
[wsl2]
memory=16GB
swap=32GB
processors=16

离线安装

问题就是在线下载不下来,微软提供了旧版 WSL 的手动安装步骤 | Microsoft Learn,手动进行下载

可以先搞个下载工具AB 下载管理器进行并行下载,或者在github上下载A Download Manager that speeds up your downloads,国内github下载也很慢,可以用镜像下载

wget "https://v6.gh-proxy.org/https://github.com/amir1376/ab-download-manager/releases/download/v1.8.7/ABDownloadManager_1.8.7_windows_x64.exe"

下载完成后双击安装即可。

apt换源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
sudo sed -i 's@http://security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
sudo apt update
sudo apt upgrade

安装python依赖

安装python和uv

sudo apt install -y python3 python3-pip
pip install uv -i https://pypi.tuna.tsinghua.edu.cn/simple

编辑 ~/.bashrc,替换uv的源

export PATH="$HOME/.local/bin:$PATH"
export UV_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
export UV_PYTHON_INSTALL_MIRROR="https://mirrors.tuna.tsinghua.edu.cn"
export UV_CACHE_DIR="/path/to/your/new_cache"
source ~/.bashrc

然后安装python依赖

export BUILD_CUDA_EXT=0
uv pip install -r requirements.txt
uv pip install modelscope

如果使用高版本的python,可能会出现

ModuleNotFoundError: No module named 'pkg_resources'

setuptools v82.0.0 发布之后,该版本正式彻底移除了 pkg_resources

v82.0.0

08 Feb 2026

Deprecations and Removals

pkg_resources has been removed from Setuptools. Most common uses of pkg_resources have been superseded by the importlib.resources and importlib.metadata projects. Projects and environments relying on pkg_resources for namespace packages or other behavior should depend on older versions of setuptools. (#3085)


你需要安装一个还保留有 pkg_resources 的旧版本(v81 或更低):
```shell
uv pip install "setuptools<81"