初始提交
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env powershell
|
||||
# -*- coding: utf-8 -*-
|
||||
<#
|
||||
.SYNOPSIS
|
||||
壁纸更换器 - 编译脚本
|
||||
.DESCRIPTION
|
||||
使用 PyInstaller 将 Python 源码打包为单个 .exe 文件。
|
||||
输出: .\dist\WallpaperChanger.exe
|
||||
#>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host " 壁纸更换器 - 编译打包" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[1/4] 激活 conda 环境 ..." -ForegroundColor Yellow
|
||||
conda activate 312
|
||||
if ($LASTEXITCODE -ne 0) { throw "激活 conda 环境失败 (312)" }
|
||||
|
||||
Write-Host "[2/4] 安装编译依赖 ..." -ForegroundColor Yellow
|
||||
python -m pip install pyinstaller --quiet
|
||||
if ($LASTEXITCODE -ne 0) { throw "安装 PyInstaller 失败" }
|
||||
|
||||
python -m pip install -r "$ScriptDir\requirements.txt" --quiet
|
||||
|
||||
Write-Host "[3/4] 清理旧产物 ..." -ForegroundColor Yellow
|
||||
Remove-Item -Recurse -Force "$ScriptDir\dist" -ErrorAction SilentlyContinue
|
||||
Remove-Item -Recurse -Force "$ScriptDir\build" -ErrorAction SilentlyContinue
|
||||
Remove-Item -Force "$ScriptDir\*.spec" -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "[4/4] PyInstaller 打包 ..." -ForegroundColor Yellow
|
||||
Set-Location -LiteralPath $ScriptDir
|
||||
python -m PyInstaller `
|
||||
--onefile `
|
||||
--noconsole `
|
||||
--name "WallpaperChanger" `
|
||||
--clean `
|
||||
"$ScriptDir\main.py"
|
||||
|
||||
if ($LASTEXITCODE -ne 0) { throw "PyInstaller 打包失败" }
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " 编译完成!" -ForegroundColor Green
|
||||
Write-Host " 输出: $ScriptDir\dist\WallpaperChanger.exe" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Reference in New Issue
Block a user