PCM_Report/install_sql_libs.ps1

48 lines
1.3 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.

# 安装SQL Server相关库
Write-Host "安装SQL Server相关库..." -ForegroundColor Yellow
# 激活虚拟环境
if (Test-Path .\.venv\Scripts\Activate.ps1) {
. .\.venv\Scripts\Activate.ps1
Write-Host "已激活虚拟环境" -ForegroundColor Green
} else {
Write-Host "虚拟环境不存在,请先创建虚拟环境" -ForegroundColor Red
return
}
# 安装pyodbc
Write-Host "安装pyodbc..." -ForegroundColor Cyan
pip install pyodbc==5.0.1
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ pyodbc安装成功" -ForegroundColor Green
} else {
Write-Host "❌ pyodbc安装失败" -ForegroundColor Red
}
# 安装pymssql
Write-Host "安装pymssql..." -ForegroundColor Cyan
pip install pymssql==2.2.11
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ pymssql安装成功" -ForegroundColor Green
} else {
Write-Host "❌ pymssql安装失败" -ForegroundColor Red
}
# 测试导入
Write-Host "测试库导入..." -ForegroundColor Yellow
python -c "
try:
import pyodbc
print('✅ pyodbc导入成功')
except Exception as e:
print(f'❌ pyodbc导入失败: {e}')
try:
import pymssql
print('✅ pymssql导入成功')
except Exception as e:
print(f'❌ pymssql导入失败: {e}')
"
Write-Host "SQL Server库安装完成" -ForegroundColor Green