69 lines
2.3 KiB
PowerShell
69 lines
2.3 KiB
PowerShell
# 紧急修复脚本 - 恢复正常运行环境
|
||
Write-Host "紧急修复 - 恢复Python环境" -ForegroundColor Red
|
||
Write-Host "=" * 50
|
||
|
||
# 1. 强制终止所有Python进程
|
||
Write-Host "1. 终止Python进程..." -ForegroundColor Yellow
|
||
Get-Process -Name "python*" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||
Start-Sleep -Seconds 2
|
||
|
||
# 2. 删除损坏的虚拟环境
|
||
Write-Host "2. 删除损坏的虚拟环境..." -ForegroundColor Yellow
|
||
if (Test-Path .\.venv) {
|
||
try {
|
||
Remove-Item .\.venv -Recurse -Force -ErrorAction Stop
|
||
Write-Host "已删除虚拟环境" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host "无法删除虚拟环境,请手动删除 .venv 文件夹" -ForegroundColor Red
|
||
Write-Host "然后重新运行此脚本" -ForegroundColor Yellow
|
||
return
|
||
}
|
||
}
|
||
|
||
# 3. 重新创建干净的虚拟环境
|
||
Write-Host "3. 创建新的虚拟环境..." -ForegroundColor Yellow
|
||
python -m venv .venv
|
||
if (-not $?) {
|
||
Write-Host "创建虚拟环境失败,请检查Python安装" -ForegroundColor Red
|
||
return
|
||
}
|
||
|
||
# 4. 激活虚拟环境
|
||
Write-Host "4. 激活虚拟环境..." -ForegroundColor Yellow
|
||
. .\.venv\Scripts\Activate.ps1
|
||
|
||
# 5. 升级pip
|
||
Write-Host "5. 升级pip..." -ForegroundColor Yellow
|
||
python -m pip install --upgrade pip
|
||
|
||
# 6. 安装基础依赖
|
||
Write-Host "6. 安装基础依赖..." -ForegroundColor Yellow
|
||
pip install PySide6==6.7.0
|
||
pip install python-docx==0.8.11
|
||
pip install pandas==2.2.2
|
||
pip install matplotlib==3.8.4
|
||
pip install influxdb-client==1.43.0
|
||
pip install pymodbus==3.6.2
|
||
pip install paramiko==3.4.0
|
||
pip install psutil==5.9.8
|
||
|
||
# 7. 测试Python环境
|
||
Write-Host "7. 测试Python环境..." -ForegroundColor Yellow
|
||
python -c "import sys; print(f'Python版本: {sys.version}')"
|
||
python -c "import PySide6; print('PySide6导入成功')"
|
||
python -c "import influxdb_client; print('InfluxDB客户端导入成功')"
|
||
python -c "import pymodbus; print('Pymodbus导入成功')"
|
||
|
||
# 8. 测试主程序
|
||
Write-Host "8. 测试主程序导入..." -ForegroundColor Yellow
|
||
python -c "
|
||
try:
|
||
from ui_main import MainWindow
|
||
print('✅ 主程序导入成功')
|
||
except Exception as e:
|
||
print(f'❌ 主程序导入失败: {e}')
|
||
"
|
||
|
||
Write-Host "紧急修复完成!" -ForegroundColor Green
|
||
Write-Host "现在可以尝试运行: python main.py" -ForegroundColor Green
|