在windows 10上安装linux子系统

参考资料:
https://learn.microsoft.com/zh-cn/windows/wsl/install
https://learn.microsoft.com/zh-cn/windows/wsl/basic-commands#install
参考博客:
https://blog.csdn.net/huiruwei1020/article/details/107551106

1、在控制面板中勾选适用于linux的windows子系统

image

勾选确认后重启即可

打开开发者模式
image

2、WSL一些常用命令

打开windows powershell
image

  • 查看可通过在线商店获得的 Linux 发行版列表
wsl --list --online

image

  • 列出已安装的 Linux 发行版
wsl --list --verbose

image

  • 检查 WSL 状态
    查看有关 WSL 配置的常规信息,例如默认发行版类型、默认发行版和内核版本。
wsl --status

image

  • Help 命令
wsl --help

image

3、安装WSL

使用管理员权限打开powershell
启用“适用于 Linux 的 Windows 子系统”可选功能

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

image

这时候wsl其实已经启用了,重启就可以了,但还要更新到wsl2,就在后面一起重启了。

升级到WSL2
启用“虚拟机平台”可选组件

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

image

重启电脑。重新管理员身份打开powershell,用下面的命令将wsl2设置为默认。

wsl --set-default-version 2

image

安装linux分发版

选择一个你喜欢的就可以了,任君挑选。
打开 Microsoft Store,并选择你偏好的 Linux 分发版。
https://aka.ms/wslstore
或者直接进微软商店下载吧
image
image

安装完重启
image
重启后打开ubantu子系统,然后设置用户名密码即可

ubantu子系统的路径比较奇怪,在此电脑中拉到下面可以找到ubantu子系统,但是看路径是比较奇怪的
image

4、安装Windows Terminal终端

微软商店下载即可
image
安装完可以在终端直接打开ubantu
image

5、在pycharm接入WSL2开发环境

5.1 先在wsl2的ubantu安装好python的conda环境

安装anaconda
https://www.cnblogs.com/yechangxin/articles/16849246.html
配置conda环境
https://www.cnblogs.com/yechangxin/articles/16923696.html

5.2 在pycharm中使用WSL2的conda开发环境

image
image
image
image
弄好环境后,可以在pycharm直接打开ubantu的代码目录
image
image

6、遇到的坑

6.1 WslRegisterDistribution failed with error: 0x800701bc报错

image

解决方法
造成该问题的原因是WSL版本由原来的WSL1升级到WSL2后,内核没有升级,前往微软WSL官网下载安装适用于 x64 计算机的最新 WSL2 Linux 内核更新包即可。
下载链接:https://learn.microsoft.com/zh-cn/windows/wsl/install-manual
或者直接
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
image
完美解决!!!
image

posted @ 2023-03-30 20:59  JaxonYe  阅读(99)  评论(0编辑  收藏  举报