PCM_Report/build_simple.ps1

64 lines
1.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Param(
[string]$Name = "docx_creator"
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
Write-Host "简化构建脚本 - 避免权限问题" -ForegroundColor Green
Write-Host "=" * 50
# 进入脚本目录
Set-Location -Path $PSScriptRoot
# 1. 激活虚拟环境(如果存在)
if (Test-Path .\.venv\Scripts\Activate.ps1) {
Write-Host "激活虚拟环境..." -ForegroundColor Yellow
. .\.venv\Scripts\Activate.ps1
} else {
Write-Host "创建虚拟环境..." -ForegroundColor Yellow
python -m venv .venv
. .\.venv\Scripts\Activate.ps1
}
# 2. 安装依赖(跳过已安装的)
Write-Host "检查依赖..." -ForegroundColor Yellow
pip install --upgrade pip --quiet
pip install -r requirements.txt --quiet
pip install pyinstaller --quiet
# 3. 确保配置文件存在
if ((Test-Path .\config.json) -and -not (Test-Path .\default.json)) {
Copy-Item .\config.json .\default.json -Force
}
# 4. 使用简单的PyInstaller命令不清理旧文件
Write-Host "开始构建..." -ForegroundColor Yellow
$buildArgs = @(
"--name", $Name,
"--windowed",
"--noconfirm",
"--collect-all", "PySide6",
"--hidden-import", "PySide6.QtCore",
"--hidden-import", "PySide6.QtGui",
"--hidden-import", "PySide6.QtWidgets",
"--hidden-import", "influxdb_client",
"--hidden-import", "pymodbus",
"--hidden-import", "sqlite3",
"--hidden-import", "pyodbc",
"--hidden-import", "pymssql",
"--add-data", "style.qss;.",
"--add-data", "default.json;.",
"main.py"
)
try {
pyinstaller @buildArgs
Write-Host "构建成功!" -ForegroundColor Green
Write-Host "输出目录: $(Join-Path $PSScriptRoot 'dist' $Name)" -ForegroundColor Green
} catch {
Write-Host "构建失败: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "尝试运行权限修复脚本: .\fix_permissions.ps1 -Force" -ForegroundColor Yellow
}