Day 1任务:Windows 开发环境搭建
目标:把 Python、Git、Docker、PHP、Composer 全部装好并验证通过。
预计耗时:1.5–2 小时(含下载等待)。
验收标准:5 条命令全部输出版本号,Docker Desktop 显示 WSL2 引擎运行中。
0. 开始前的检查(10 分钟)
0.1 系统版本确认
按Win + R,输入winver,回车。
要求:
- Windows 10 版本 ≥ 2004(内部版本 19041+)
- 或 Windows 11 任意版本
如果低于 2004,先 Windows Update 升级。WSL2 需要这个版本。
0.2 磁盘空间确认
打开「此电脑」,确认D 盘剩余 ≥ 40GB。
用途预估:
| 项目 | 占用 |
|---|---|
| Python + venv + PyTorch CUDA | 约 8GB |
| Docker Desktop + Hyperf 镜像 | 约 6GB |
| Qwen2.5-Coder-0.5B 模型 | 约 1GB |
| 数据、输出、日志 | 约 5GB |
| 余量 | 20GB |
如果 D 盘不够,用 C 盘,但后续所有路径改成C:\hyperf-coder。
0.3 虚拟化确认
按Ctrl + Shift + Esc打开任务管理器 → 性能 → CPU。
右下角应显示虚拟化:已启用。
如果显示「已禁用」:
- 重启电脑,进 BIOS(一般 F2 / Del / F10)
- 找到
Intel VT-x或Virtualization Technology - 设为 Enabled
- 保存重启
没有虚拟化,Docker Desktop 无法运行。
0.4 关闭冲突软件
暂时关闭或卸载:
- 旧版 Docker Toolbox
- VirtualBox(与 Hyper-V 冲突,Docker Desktop 用 WSL2 时也可能冲突)
- 360 安全卫士 / 腾讯电脑管家(会拦 winget 安装)
- 代理软件先记下端口,后面可能要配
0.5 确认 winget 可用
打开PowerShell(管理员):
开始菜单 → 输入PowerShell→ 右键 → 以管理员身份运行。
winget--version期望输出:v1.6.x或更高。
如果没有 winget:
- 打开 Microsoft Store
- 搜索「应用安装程序」
- 安装/更新
- 重开 PowerShell 再试
1. 安装 Git(10 分钟)
winget install--id Git.Git-e--source winget参数说明:
--id Git.Git:精确指定包 ID-e:精确匹配,避免装错--source winget:从 winget 源装
安装过程会弹 UAC,点「是」。
装完后关闭当前 PowerShell,重新以管理员打开(让 PATH 生效)。
验证:
git--version期望:git version 2.4x.x.windows.1
配置身份(后面 commit 要用):
git config--global user.name"你的名字"git config--global user.email"你的邮箱@example.com"git config--global init.defaultBranch main git config--global core.autocrlf true验证:
git config--global--list2. 安装 Python 3.11(10 分钟)
winget install--id Python.Python.3.11-e--source winget不要装 3.12/3.13,部分库(尤其 trl、peft 旧版本)兼容性不如 3.11。
装完关闭 PowerShell,重新以管理员打开。
验证:
python--version pip--version期望:
Python 3.11.x pip 24.x from ... (python 3.11)如果python命令找不到:
- 打开「设置 → 应用 → 高级应用设置 → 应用执行别名」
- 关闭
python.exe和python3.exe的别名 - 重开 PowerShell
升级 pip:
python-m pip install--upgrade pip setuptools wheel3. 安装 PHP 8.3(10 分钟)
winget install--id PHP.PHP.8.3-e--source winget装完重开 PowerShell。
验证:
php--version期望:PHP 8.3.x (cli)
如果没找到,手动加 PATH:
- 找到
C:\php或C:\Program Files\PHP\v8.3 - 系统属性 → 环境变量 → Path → 新增该目录
- 重开 PowerShell
配置 php.ini(可选,为了php -l和 composer 正常):
# 找到 php.ini 位置php--ini如果显示没有 php.ini,复制一份模板:
# 假设 PHP 在 C:\phpcopyC:\php\php.ini-development C:\php\php.ini编辑C:\php\php.ini,取消注释:
extension=curl extension=mbstring extension=openssl extension=fileinfo保存后验证:
php-m应看到 curl、mbstring、openssl、fileinfo。
4. 安装 Composer(10 分钟)
Composer 不在 winget 里,手动装:
# 下载安装器php-r"copy('https://getcomposer.org/installer', 'composer-setup.php');"# 校验(可选,但推荐)php-r"if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b') { echo 'Verifier OK' . PHP_EOL; } else { echo 'Verifier FAIL' . PHP_EOL; }"# 安装到当前目录php composer-setup.php# 删除安装器php-r"unlink('composer-setup.php');"# 移到全局mkdir C:\bin-Forcemovecomposer.phar C:\bin\composer.phar创建C:\bin\composer.bat:
Set-Content-Path C:\bin\composer.bat-Value"@php `"%~dp0composer.phar`" %*"加 PATH:
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path","User")+";C:\bin","User")关闭并重新打开 PowerShell(必须,PATH 才生效)。
验证:
composer--version期望:Composer version 2.7.x
5. 安装 Docker Desktop(30–60 分钟,含下载)
winget install--id Docker.DockerDesktop-e--source winget下载约 500MB,安装 5–10 分钟。
安装时勾选:
- ✅ Use WSL 2 instead of Hyper-V
- ✅ Add shortcut to desktop
装完不要立即启动,先装 WSL2。
5.1 安装 WSL2
wsl--install这会自动:
- 启用「适用于 Linux 的 Windows 子系统」
- 启用「虚拟机平台」
- 下载 WSL2 内核
- 安装 Ubuntu 默认发行版
装完必须重启电脑。
重启后,Ubuntu 会自动打开,要求设置:
Enter new UNIX username: yourname New password: (输入时不显示,正常) Retype new password:记住这个用户名密码,后面 Docker 要用。
验证 WSL2:
wsl--list--verbose期望:
NAME STATE VERSION * Ubuntu Running 2VERSION必须是2。如果是 1:
wsl--set-versionUbuntu 2 wsl--set-default-version 25.2 启动 Docker Desktop
双击桌面图标启动。首次启动会:
- 接受服务协议
- 跳过登录(点 Skip)
- 跳过问卷
- 等待引擎启动(左下角鲸鱼图标变绿)
打开 Docker Desktop → 右上角齿轮 Settings:
- General:勾选
Use the WSL 2 based engine - Resources → WSL Integration:勾选
Enable integration with my default WSL distro和Ubuntu - Apply & Restart
验证:
docker--version docker compose version docker run hello-world期望:
Docker version 27.x.x Docker Compose version v2.x.x Hello from Docker!如果docker run hello-world卡住,检查:
- Docker Desktop 左下角是否绿色
- WSL2 是否在运行:
wsl --list --verbose - 是否需要开代理(见第 7 节)
6. 安装 VS Code(10 分钟)
winget install--id Microsoft.VisualStudioCode-e--source winget装完打开 VS Code,装扩展(Ctrl+Shift+X 搜索安装):
| 扩展 | 用途 |
|---|---|
| Python | Python 支持 |
| Pylance | 类型提示 |
| Jupyter | Notebook |
| Docker | 容器管理 |
| Remote - WSL | WSL 开发 |
| PHP Intelephense | PHP 智能提示 |
| Chinese (Simplified) | 中文界面(可选) |
7. 网络问题处理(重要)
国内网络下,winget / pip / docker 可能很慢或失败。
7.1 pip 换源
pip configsetglobal.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip configsetglobal.trusted-host pypi.tuna.tsinghua.edu.cn验证:
pip config list7.2 Docker 换镜像源
Docker Desktop → Settings → Docker Engine,修改 JSON:
{"registry-mirrors":["https://docker.m.daocloud.io","https://dockerproxy.com","https://mirror.baidubce.com"]}Apply & Restart。
验证:
docker pull hello-world7.3 HuggingFace 换源(D3 之后用)
[Environment]::SetEnvironmentVariable("HF_ENDPOINT","https://hf-mirror.com","User")重开 PowerShell 生效。
8. 建立项目目录(10 分钟)
cd D:\ mkdir hyperf-coder cd hyperf-coder mkdirdatamkdirdata\raw mkdirdata\processed mkdir scripts mkdir outputs mkdir logs mkdir reports mkdir hyperf_sandbox mkdir colab# 初始化 gitgit init创建.gitignore:
@" venv/ __pycache__/ *.pyc outputs/ logs/ data/raw/ data/processed/ hyperf_sandbox/workspace/ chroma_db/ *.gguf *.safetensors .env "@|Out-File-Encoding utf8.gitignore创建README.md:
@" # Hyperf Coder 基于 Qwen2.5-Coder-0.5B 微调的 Hyperf 代码助手。 ## 环境 - Windows 10/11 - Python 3.11 - PyTorch CUDA 12.1 - GTX 1660 Ti 6GB - Docker Desktop + WSL2 ## 目录 - data/ 数据 - scripts/ 脚本 - outputs/ 模型输出 - hyperf_sandbox/ Hyperf 沙箱 - reports/ 评估报告 "@|Out-File-Encoding utf8 README.md首次 commit:
git add.git commit-m"chore: init project structure"9. Day 1 验收清单
逐条打勾:
[ ] winver 显示 Windows 10 2004+ 或 Windows 11 [ ] 任务管理器显示虚拟化已启用 [ ] D 盘剩余 ≥ 40GB [ ] git --version 输出版本号 [ ] python --version 输出 3.11.x [ ] pip --version 输出 24.x [ ] php --version 输出 8.3.x [ ] php -m 包含 curl/mbstring/openssl/fileinfo [ ] composer --version 输出 2.7.x [ ] docker --version 输出 27.x [ ] docker compose version 输出 v2.x [ ] docker run hello-world 成功 [ ] wsl --list --verbose 显示 VERSION 2 [ ] VS Code 已装并装好扩展 [ ] D:\hyperf-coder 目录结构创建完成 [ ] git commit 成功全部打勾,Day 1 完成。
10. 一条命令总验证
把下面整段粘到 PowerShell 跑:
Write-Host"===== Day 1 环境验收 ====="-ForegroundColor CyanWrite-Host"`n[1] Git"-ForegroundColor Yellow git--versionWrite-Host"`n[2] Python"-ForegroundColor Yellow python--version pip--versionWrite-Host"`n[3] PHP"-ForegroundColor Yellow php--version|Select-Object-First 1 php-m|Select-String"curl|mbstring|openssl|fileinfo"Write-Host"`n[4] Composer"-ForegroundColor Yellow composer--versionWrite-Host"`n[5] Docker"-ForegroundColor Yellow docker--version docker compose versionWrite-Host"`n[6] WSL"-ForegroundColor Yellow wsl--list--verboseWrite-Host"`n[7] 项目目录"-ForegroundColor YellowGet-ChildItemD:\hyperf-coder|Select-ObjectNameWrite-Host"`n===== 验收结束 ====="-ForegroundColor Cyan期望看到每项都有版本号,没有红色报错。
11. 常见故障排查
问题 1:winget 报「找不到源」
winget source update winget source list如果源损坏:
winget source reset--force问题 2:Python 命令打开 Microsoft Store
「设置 → 应用 → 高级应用设置 → 应用执行别名」,关闭python.exe和python3.exe。
问题 3:Docker Desktop 启动卡在 “Starting…”
先确认 WSL2 正常:
wsl--shutdown wsl--list--verbose再重启 Docker Desktop。还不行:
# 重置 Docker 网络docker network prune-f问题 4:wsl --install报 0x800701bc
说明 WSL2 内核没装:
- 下载 https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
- 安装
- 重跑
wsl --install
问题 5:Composer 校验失败
跳过校验直接装:
php-r"copy('https://getcomposer.org/installer', 'composer-setup.php');"php composer-setup.php--no-check php-r"unlink('composer-setup.php');"问题 6:公司网络/代理
如果公司网络有代理,winget 和 docker 需要配:
# winget 代理winget settingssetnetwork.proxy http://proxy.company.com:8080# Docker Desktop → Settings → Resources → Proxies 填代理12. Day 1 结束时的状态
你应该有:
D:\hyperf-coder\ ├── .git\ ├── .gitignore ├── README.md ├── data\ │ ├── raw\ │ └── processed\ ├── scripts\ ├── outputs\ ├── logs\ ├── reports\ ├── hyperf_sandbox\ └── colab\外部工具:
- Git 2.4x
- Python 3.11
- PHP 8.3
- Composer 2.7
- Docker Desktop + WSL2 Ubuntu
- VS Code + 扩展
13. Day 1 结束语
Day 1 只做环境,不碰模型、不碰数据、不碰训练。
环境稳,后面 11 周才稳。遇到报错不要跳过,逐条解决。
Day 2 预告:
- 建 Python venv
- 装 CUDA 版 PyTorch
- 验证
torch.cuda.is_available()返回 True - 验证
GTX 1660 Ti被识别