# 启用 Windows 长路径支持(需要管理员权限) # 运行后重启电脑生效 Write-Host "========================================" -ForegroundColor Cyan Write-Host "启用 Windows 长路径支持" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # 检查是否以管理员身份运行 if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Host "❌ 请以管理员身份运行 PowerShell 后再执行此脚本" -ForegroundColor Red Write-Host " 右键点击 PowerShell -> 以管理员身份运行" -ForegroundColor Yellow pause exit } # 启用长路径支持 Write-Host "正在启用长路径支持..." -ForegroundColor Yellow try { Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 Write-Host "✅ 注册表修改成功" -ForegroundColor Green } catch { Write-Host "❌ 修改失败: $_" -ForegroundColor Red pause exit } # 启用 Python 长路径支持 Write-Host "" Write-Host "Python 长路径环境变量:" -ForegroundColor Yellow $envVar = [Environment]::GetEnvironmentVariable("PYTHONLEGACYWINDOWSFSENCODING", "User") if ($envVar -eq $null) { [Environment]::SetEnvironmentVariable("PYTHONLEGACYWINDOWSFSENCODING", "1", "User") Write-Host "✅ 已设置 PYTHONLEGACYWINDOWSFSENCODING=1" -ForegroundColor Green } else { Write-Host " 已存在: PYTHONLEGACYWINDOWSFSENCODING=$envVar" -ForegroundColor Cyan } Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host "✅ 设置完成!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" Write-Host "注意: 需要重启电脑才能完全生效" -ForegroundColor Yellow Write-Host "" pause