win11使用wsl部署linux子系统(ubuntu)
1.打开Windows的三个虚拟化功能
注:Windows 11 家庭版需安装 Hyper-V
复制以下批处理代码,新建空白文本后保存,保存更改文本 .txt 后缀为 .bat 格式。右键以管理员身份运行即可。
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
pause
重启电脑之后勾选即可。
2.安装linux子系统
下载wsl
下载地址:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
在Microsoft Store下载Ubuntu
在应用商店点击获取之后,会自动下载,完成后点击“安装”,弹出一个DOS窗口按任意键安装。根据提示完成安装(期间会让你设置用户名和密码),完成后下次登录只需要在PowerShell或CMD窗口输入“WSL”即可打开Ubuntu系统
3.wsl迁移到其他盘
wsl默认下到c盘,后续可能占据内存会比较多,如果c盘不够大,可以移动到其他数据盘
参考这个博客
https://blog.csdn.net/weixin_42705114/article/details/131106845
4.安装Anaconda
下载annaconda
https://www.anaconda.com/download/success
将下载的文件拷入到指定目录/mnt(自己指定)
cd到当前目录
cd /mnt
bash Anaconda3-2023.09-0-Linux-x86_64.sh
按PageDOWN快速跳过协议,输入yes安装
加入环境变量
echo 'export PATH="/home/cyber(这里改成你自己的用户名)/anaconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
安装完成以后,可以查看版本号
查看conda版本:conda -V
查看python版本: python -V
5.创建虚拟环境
# 创建虚拟环境
conda create -n 虚拟环境名称 python=3.10
#查看环境
conda info -e
#激活环境
conda activate 虚拟环境名称
#退出环境
deactivate
6.安装pip
sudo apt update
apt install python3-pip
7.更换镜像源
mkdir ~/.pip
vi ~/.pip/pip.conf
将以下粘贴进去,:wq 保存退出
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple