62 lines
1.8 KiB
PowerShell
62 lines
1.8 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "[1/6] 设置项目 Python 3.12.10"
|
|
pyenv local 3.12.10
|
|
|
|
Write-Host "[2/6] 通过 pyenv 获取项目 Python"
|
|
$Python312 = (pyenv which python | Select-Object -First 1).Trim()
|
|
|
|
if (-not $Python312) {
|
|
throw "pyenv which python 未返回 Python 路径"
|
|
}
|
|
if (-not (Test-Path $Python312)) {
|
|
throw "pyenv 返回的 Python 不存在: $Python312"
|
|
}
|
|
|
|
$Version = (& $Python312 --version 2>&1).Trim()
|
|
Write-Host "Python executable: $Python312"
|
|
Write-Host "Python version: $Version"
|
|
|
|
if ($Version -ne "Python 3.12.10") {
|
|
throw "项目要求 Python 3.12.10,但 pyenv 当前返回: $Version"
|
|
}
|
|
|
|
Write-Host "[3/6] 检查/创建虚拟环境"
|
|
if (Test-Path ".venv\Scripts\python.exe") {
|
|
$ExistingVersion = (& ".\.venv\Scripts\python.exe" --version 2>&1).Trim()
|
|
if ($ExistingVersion -ne "Python 3.12.10") {
|
|
Write-Host "发现错误虚拟环境 ($ExistingVersion),正在删除..."
|
|
Remove-Item -Recurse -Force ".venv"
|
|
}
|
|
}
|
|
|
|
if (-not (Test-Path ".venv\Scripts\python.exe")) {
|
|
& $Python312 -m venv .venv
|
|
}
|
|
|
|
$VenvPython = (Resolve-Path ".\.venv\Scripts\python.exe").Path
|
|
$VenvVersion = (& $VenvPython --version 2>&1).Trim()
|
|
Write-Host "Venv Python: $VenvVersion"
|
|
|
|
if ($VenvVersion -ne "Python 3.12.10") {
|
|
throw "虚拟环境 Python 版本错误: $VenvVersion"
|
|
}
|
|
|
|
Write-Host "[4/6] 升级 pip"
|
|
& $VenvPython -m pip install --upgrade pip
|
|
|
|
Write-Host "[5/6] 安装项目"
|
|
& $VenvPython -m pip install -e .
|
|
|
|
$Cm93Db = (Resolve-Path ".\.venv\Scripts\cm93db.exe").Path
|
|
|
|
Write-Host "[6/6] 基础命令检查"
|
|
& $Cm93Db --help
|
|
|
|
Write-Host ""
|
|
Write-Host "Python 3.12.10 虚拟环境已建立。"
|
|
Write-Host "下一步:"
|
|
Write-Host " 1. Copy-Item .env.example .env"
|
|
Write-Host " 2. 修改 .env 中的 MySQL 5.7.34 参数"
|
|
Write-Host " 3. .\scripts\init_db.ps1"
|