0. 背景和简介
今天(2023/6/2)刚刚换了 1 块 4TB 的硬盘,在 Windows 11 上从零开始,基于 Windows Subsystem for Linux 搭建一套 AI 学习环境。
其中包括,安装 Python、安装 Miniconda3、安装 CUDA Toolkit、安装 git lfs、配置 Hugging Face 的缓存路径、本地部署 ChatGLM-6B、本地部署 VisualGLM-6B等等内容。
1. 安装 wsl-ubuntu
- 安装 Ubuntu-22.04,默认会安装在 C 盘,
wsl.exe --install -d Ubuntu-22.04
- 导出 Ubuntu-22.04,
wsl --export Ubuntu-22.04 D:\tmp\Ubuntu-22.04.tar
- 删除 Ubuntu-22.04,
wsl --unregister Ubuntu-22.04
- 导入 Ubuntu-22.04,导入到
F:\VirtualPCs\Ubutun-22.04
目录,
wsl --import Ubuntu-22.04 F:\VirtualPCs\Ubutun-22.04 D:\tmp\Ubuntu-22.04.tar
- 访问 Ubuntu-22.04,
wsl
- 退出 Ubuntu-22.04,
exit
- (可选)关闭 Ubuntu-22.04,
wsl --shutdown
2. (可选)配置清华大学软件源
- 为了加速软件安装速度,配置清华大学软件源,
mv /etc/apt/sources.list /etc/apt/sources.list.bak
cat << EOF > /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF
3. 系统更新
sudo apt update && sudo apt upgrade
4. 安装 Python
- 安装必要的构建工具,
sudo apt install build-essential checkinstall
sudo apt install libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
- 下载Python 3.10.6 源代码,
cd /tmp
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
tar -xvf Python-3.10.6.tar.xz
cd Python-3.10.6/
- 配置和安装Python 3.10,
./configure --enable-optimizations
sudo make altinstall
altinstall
选项会安装Python 3.10到/usr/bin/python3.10
,这样不会对系统默认的Python产生影响。文章来源:https://www.toymoban.com/news/detail-469394.html
- (可选)配置环境变量,
echo 'export PATH="/usr/bin/python3.10:$PATH"' >> ~/.bashrc
source ~/.bashrc
- 配置软链接,
ln -s /usr/local/bin/python3.10 /usr/local/bin/python3
ln -s /usr/local/bin/python3.10 /usr/local/bin/python
ln -s /usr/local/bin/pip3.10 /usr/local/bin/pip3
ln -s /usr/local/bin/pip3.10 /usr/local/bin/pip
- 验证Python 3.10是否安装成功,
python3 --version
--- 输出
Python 3.10.6
---
pip3 --version
--- 输出
pip 22.2.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
---
5. 安装 Miniconda3
- 下载 Conda 安装脚本,
cd /tmp
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
- 运行安装脚本,按提示操作,当提示是否初始化 Conda 时,输入 “yes”,
bash Miniconda3-latest-Linux-x86_64.sh
---
Please, press ENTER to continue
>>> yes
Do you accept the license terms? [yes|no]
[no] >>> yes
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/miniconda3] >>> ENTER
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
---
- 安装完成后,激活一下 Conda,
sudo su - root
- 更新 Conda 至最新版本,
conda update conda
- 配置用户登录时是否默认激活 Conda 的 base 环境,
如果想默认激活 Conda 的 base 环境,文章来源地址https://www.toymoban.com/news/detail-469394.html
conda config --set auto_activate_base true
到了这里,关于Windows 11 上从零开始基于 wsl-ubuntu 搭建 AI 学习环境及部署多种私有 ChatGPT的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!