完美解决无法加载文件 WindowsPowerShell\profile.ps1系统编译问题

1、问题描述

在这里插入图片描述

2、解决方法

这个错误是由于 PowerShell 的执行策略设置限制了脚本的运行。你可以通过以下步骤来解决这个问题:

步骤 1:以管理员身份运行 PowerShell

  1. Win + X 键,选择“Windows PowerShell (管理员)”或“Windows PowerShell (Admin)”。
  2. 或者在开始菜单中搜索“PowerShell”,右键点击“Windows PowerShell”,选择“以管理员身份运行”。

步骤 2:检查当前的执行策略

在管理员 PowerShell 窗口中输入以下命令查看当前的执行策略:

Get-ExecutionPolicy -List

在这里插入图片描述

步骤 3:更改执行策略

为了允许运行脚本,你可以将执行策略更改为 RemoteSignedUnrestricted。例如,设置为 RemoteSigned(允许运行本地脚本和来自受信任来源的远程脚本):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

在这里插入图片描述

如果你需要为所有用户设置执行策略,可以使用 -Scope LocalMachine 参数:

Set-ExecutionPolicy RemoteSigned -Scope LocalMachine

步骤 4:确认更改

PowerShell 会提示你确认更改。输入 Y 并按回车键确认。

步骤 5:重新运行脚本

现在你应该能够运行脚本了。再次尝试运行你的脚本,确保它能够正常执行。

3、验证解决方法

如果你仍然遇到问题,可以按照以下步骤进行进一步的排查:
在这里插入图片描述

3.1. 验证脚本路径和权限

确保你的脚本路径正确并且脚本文件具有适当的权限。可以尝试以下命令来检查和设置脚本文件的权限:

Get-Item "C:\Users\Administrator\Documents\WindowsPowerShell\profile.ps1" | Format-List * -Force

在这里插入图片描述

如果需要更改权限,可以使用以下命令:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

3.2. 检查是否存在 profile.ps1

确保路径 C:\Users\Administrator\Documents\WindowsPowerShell\profile.ps1 下存在 profile.ps1 文件。如果不存在,可以手动创建该文件。

3.3. 运行 PowerShell 脚本

尝试运行一个简单的 PowerShell 脚本来验证设置是否成功:

Write-Output "Hello, PowerShell!"

在这里插入图片描述

3.4. 重启 PowerShell

重启 PowerShell 窗口,确保新设置生效。

3.5. 使用 Bypass 策略临时运行脚本

如果你只需要临时运行某个脚本,可以使用 Bypass 策略:

powershell -ExecutionPolicy Bypass -File "C:\Users\Administrator\Documents\WindowsPowerShell\profile.ps1"

3.6. 确保文件没有被锁定

有时文件可能被锁定,无法访问。可以尝试关闭所有打开的编辑器或应用程序,然后重试。

希望这些步骤能帮助你解决问题。如果问题仍然存在,请提供更多细节,以便进一步排查。

最后重新打开看看是否出现本文开头截图的红色问题:
在这里插入图片描述

PS C:\Users\Administrator\Desktop> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env Error: [Errno 13] Permission denied: 'E:\\PyTorch_Build\\pytorch\\rtx5070_env\\Scripts\\python.exe' PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 修复 PowerShell 配置文件错误 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 1: 备份当前配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $backupPath = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.bak" (rtx5070_env) PS E:\PyTorch_Build\pytorch> Copy-Item $PROFILE $backupPath -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "✅ 配置文件已备份至: $backupPath" -ForegroundColor Green ✅ 配置文件已备份至: C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.bak (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 2: 清理冲突的类型定义 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $newProfileContent = @" >> # 清理后的 PowerShell 配置文件 >> Import-Module Microsoft.PowerShell.Security -ErrorAction Stop -SkipEditionCheck >> Get-Module | Where-Object {`$_.Name -ne 'Microsoft.PowerShell.Security'} | Import-Module -Force >> "@ (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 3: 创建新的配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $newProfileContent | Out-File $PROFILE -Encoding UTF8 -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 4: 加载修复后的配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> . $PROFILE (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "✅ PowerShell 配置文件已成功修复" -ForegroundColor Green ✅ PowerShell 配置文件已成功修复 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 5: 验证修复 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-TypeData -TypeName System.Security.AccessControl.ObjectSecurity -ErrorAction SilentlyContinue TypeName Members -------- ------- System.Security.AccessControl.ObjectSecurity {[Path, System.Management.Automation.Runspaces.CodePropertyData], [Owner,… (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (-not $?) { >> Write-Host "❌ 修复失败,尝试替代方案..." -ForegroundColor Yellow >> # 替代方案:禁用冲突模块 >> Disable-Module Microsoft.PowerShell.Security -Force >> Import-Module Microsoft.PowerShell.Utility -Force >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> # cudnn_validator.ps1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $cudnnBase = "E:\Program Files\NVIDIA\CUDNN\v9.12" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $cudaVersion = "13.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $binPath = Join-Path $cudnnBase "bin\$cudaVersion" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 使用 LiteralPath 处理特殊字符路径 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $dllFiles = Get-ChildItem -LiteralPath $binPath -Filter "*.dll" -ErrorAction Stop (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (-not $dllFiles) { >> throw "❌ 在 $binPath 中未找到任何 DLL 文件" >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 查找特定模式的文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $targetDll = $dllFiles | Where-Object { $_.Name -match "cudnn_ops_infer\d+_8\.dll" } | Select-Object -First 1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (-not $targetDll) { >> # 尝试更宽松的匹配 >> $targetDll = $dllFiles | Where-Object { $_.Name -like "cudnn_ops_infer*.dll" } | Select-Object -First 1 >> >> if (-not $targetDll) { >> # 列出所有找到的 DLL 文件 >> Write-Host "🔍 在 $binPath 中找到以下 DLL 文件:" -ForegroundColor Cyan >> $dllFiles | ForEach-Object { Write-Host " - $($_.Name)" } >> >> # 尝试查找任意 cuDNN DLL >> $targetDll = $dllFiles | Where-Object { $_.Name -like "cudnn*.dll" } | Select-Object -First 1 >> } >> } 🔍 在 E:\Program Files\NVIDIA\CUDNN\v9.12\bin\13.0 中找到以下 DLL 文件: - cudnn_adv64_9.dll - cudnn_cnn64_9.dll - cudnn_engines_precompiled64_9.dll - cudnn_engines_runtime_compiled64_9.dll - cudnn_graph64_9.dll - cudnn_heuristic64_9.dll - cudnn_ops64_9.dll - cudnn64_9.dll (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> if ($targetDll) { >> # 创建所需的符号链接 >> $linkPath = Join-Path $binPath "cudnn_ops_infer64_8.dll" >> if (-not (Test-Path $linkPath)) { >> cmd /c mklink "$linkPath" "$($targetDll.FullName)" > $null >> } >> >> Write-Host "✅ 使用文件: $($targetDll.FullName)" -ForegroundColor Green >> Write-Host "✅ 已创建符号链接: $linkPath" -ForegroundColor Green >> } else { >> throw "❌ 错误: 未找到任何匹配的 cuDNN DLL 文件" >> } ✅ 使用文件: E:\Program Files\NVIDIA\CUDNN\v9.12\bin\13.0\cudnn_adv64_9.dll ✅ 已创建符号链接: E:\Program Files\NVIDIA\CUDNN\v9.12\bin\13.0\cudnn_ops_infer64_8.dll (rtx5070_env) PS E:\PyTorch_Build\pytorch> # enhanced_repair.ps1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> function Invoke-SafeRepair { >> param([string]$OperationName, [ScriptBlock]$ScriptBlock) >> >> try { >> # 减少内存占用 >> [System.GC]::Collect() >> [System.GC]::WaitForPendingFinalizers() >> >> # 设置内存限制 >> $process = Get-Process -Id $PID >> $process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::BelowNormal >> >> Write-Host "🛠️ 开始操作: $OperationName" -ForegroundColor Cyan >> >> # 执行操作 >> & $ScriptBlock >> >> Write-Host "✅ 操作成功: $OperationName" -ForegroundColor Green >> return $true >> } >> catch { >> Write-Host "❌ 操作失败: $OperationName" -ForegroundColor Red >> Write-Host "错误详情: $_" -ForegroundColor DarkRed >> >> # 创建错误报告 >> $errorReport = @" >> 操作: $OperationName >> 时间: $(Get-Date) >> 错误: $($_.Exception.Message) >> 堆栈跟踪: $($_.ScriptStackTrace) >> "@ >> >> $reportPath = "E:\PyTorch_Build\error_$((Get-Date).ToString('yyyyMMdd_HHmmss')).log" >> $errorReport | Out-File $reportPath >> Write-Host "错误报告已保存至: $reportPath" -ForegroundColor Yellow >> >> return $false >> } >> finally { >> # 恢复内存优先级 >> if ($process) { >> $process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::Normal >> } >> } >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 示例使用 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "cuDNN 配置验证" { >> .\cudnn_validator.ps1 >> } 🛠️ 开始操作: cuDNN 配置验证 ❌ 操作失败: cuDNN 配置验证 错误详情: The term '.\cudnn_validator.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001636.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "页面文件设置" { >> .\memory_protection_v4.ps1 >> } 🛠️ 开始操作: 页面文件设置 ❌ 操作失败: 页面文件设置 错误详情: The term '.\memory_protection_v4.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001636.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "编译过程" { >> .\safe_build_v4.ps1 >> } 🛠️ 开始操作: 编译过程 ❌ 操作失败: 编译过程 错误详情: The term '.\safe_build_v4.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001636.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> # memory_protection_v4.ps1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $pageFileSettings = @{ >> InitialSize = 16384 # 16GB >> MaximumSize = 32768 # 32GB >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> try { >> # 使用 WMI 替代方案 >> $pageFile = Get-WmiObject -Class Win32_PageFileSetting >> >> if ($pageFile) { >> # 使用 PowerShell 直接修改注册表(更可靠) >> $regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" >> Set-ItemProperty -Path $regPath -Name "PagingFiles" -Value "$env:SystemDrive\pagefile.sys $($pageFileSettings.InitialSize) $($pageFileSettings.MaximumSize)" -Force >> >> Write-Host "✅ 页面文件设置已更新通过注册表" -ForegroundColor Green >> } >> else { >> Write-Host "⚠️ 未找到现有页面文件配置,创建新配置..." -ForegroundColor Yellow >> Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{ >> Name = "$env:SystemDrive\pagefile.sys" >> InitialSize = $pageFileSettings.InitialSize >> MaximumSize = $pageFileSettings.MaximumSize >> } >> } >> >> # 重启内存管理服务 >> Restart-Service -Name "SysMain" -Force -ErrorAction SilentlyContinue >> } >> catch { >> Write-Host "❌ 页面文件配置失败: $_" -ForegroundColor Red >> Write-Host "⚠️ 尝试手动设置页面文件..." -ForegroundColor Yellow >> >> # 手动设置页面文件 >> $manualSettings = @" >> Windows Registry Editor Version 5.00 >> >> [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management] >> "PagingFiles"="$env:SystemDrive\pagefile.sys $($pageFileSettings.InitialSize) $($pageFileSettings.MaximumSize)" >> "@ >> >> $regFilePath = "E:\PyTorch_Build\pagefile_settings.reg" >> $manualSettings | Out-File $regFilePath >> Start-Process "regedit.exe" -ArgumentList "/s `"$regFilePath`"" -Wait >> } ✅ 页面文件设置已更新通过注册表 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 1: 修复 PowerShell 环境 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\fix_powershell_profile.ps1 .\fix_powershell_profile.ps1: The term '.\fix_powershell_profile.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 2: 验证 CUDA/cuDNN 安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "cuDNN 配置" { .\cudnn_validator.ps1 } 🛠️ 开始操作: cuDNN 配置 ❌ 操作失败: cuDNN 配置 错误详情: The term '.\cudnn_validator.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001651.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 3: 设置内存保护 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "内存配置" { .\memory_protection_v4.ps1 } 🛠️ 开始操作: 内存配置 ❌ 操作失败: 内存配置 错误详情: The term '.\memory_protection_v4.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001651.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 4: 执行安全编译 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-SafeRepair "PyTorch 编译" { .\safe_build_v4.ps1 } 🛠️ 开始操作: PyTorch 编译 ❌ 操作失败: PyTorch 编译 错误详情: The term '.\safe_build_v4.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 错误报告已保存至: E:\PyTorch_Build\error_20250904_001651.log False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # Step 5: 安装 PyTorch (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-Location E:\PyTorch_Build\pytorch (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip install -v . Using pip 22.3.1 from E:\PyTorch_Build\pytorch\rtx5070_env\lib\site-packages\pip (python 3.10) Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Processing e:\pytorch_build\pytorch
09-05
PS C:\Users\Administrator\Desktop> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate. PS E:\PyTorch_Build\pytorch> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 以管理员身份运行 Windows PowerShell 5.1 (非 PowerShell 7) (rtx5070_env) PS E:\PyTorch_Build\pytorch> $executionPolicyFix = @' >> # 1. 修复模块加载问题 >> Import-Module Microsoft.PowerShell.Security -Force >> >> # 2. 设置执行策略 >> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force >> >> # 3. 验证设置 >> Get-ExecutionPolicy -List | Format-Table -AutoSize >> '@ (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 保存并执行修复脚本 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $fixScriptPath = "$env:TEMP\FixPowerShell.ps1" (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-Content $fixScriptPath $executionPolicyFix -Encoding UTF8 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$fixScriptPath`"" -Verb RunAs -Wait (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item $fixScriptPath -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 1. 检查模块路径 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $modulePath = "$PSHOME\Modules\Microsoft.PowerShell.Security" (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "模块路径: $modulePath" 模块路径: C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Security (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 2. 验证模块文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $requiredFiles = @( >> "Microsoft.PowerShell.Security.psd1", >> "Microsoft.PowerShell.Security.psm1", >> "Microsoft.PowerShell.Security.dll" >> ) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> foreach ($file in $requiredFiles) { >> $filePath = Join-Path $modulePath $file >> if (-not (Test-Path $filePath)) { >> Write-Host "❌ 缺失文件: $file" -ForegroundColor Red >> # 从 PowerShell 7 安装目录复制文件 >> $sourceDir = "C:\Program Files\PowerShell\7\Modules\Microsoft.PowerShell.Security" >> if (Test-Path $sourceDir) { >> Copy-Item "$sourceDir\$file" $modulePath -Force >> Write-Host "✅ 已修复: $file" -ForegroundColor Green >> } >> } else { >> Write-Host "✅ 文件存在: $file" -ForegroundColor Green >> } >> } ✅ 文件存在: Microsoft.PowerShell.Security.psd1 ❌ 缺失文件: Microsoft.PowerShell.Security.psm1 Copy-Item : 找不到路径“C:\Program Files\PowerShell\7\Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psm 1”,因为该路径不存在。 所在位置 行:8 字符: 13 + Copy-Item "$sourceDir\$file" $modulePath -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program File...l.Security.psm1:String) [Copy-Item], ItemNotFoundExce ption + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand ✅ 已修复: Microsoft.PowerShell.Security.psm1 ❌ 缺失文件: Microsoft.PowerShell.Security.dll Copy-Item : 找不到路径“C:\Program Files\PowerShell\7\Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.dll ”,因为该路径不存在。 所在位置 行:8 字符: 13 + Copy-Item "$sourceDir\$file" $modulePath -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program File...ll.Security.dll:String) [Copy-Item], ItemNotFoundExce ption + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand ✅ 已修复: Microsoft.PowerShell.Security.dll (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 3. 重新导入模块 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Import-Module Microsoft.PowerShell.Security -Force -ErrorAction Stop (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "✅ 安全模块已成功加载" -ForegroundColor Green ✅ 安全模块已成功加载 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 4. 设置执行策略 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 1. 备份当前配置 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $backupDir = "$env:USERPROFILE\PSBackup_$(Get-Date -Format 'yyyyMMdd')" (rtx5070_env) PS E:\PyTorch_Build\pytorch> mkdir $backupDir -Force | Out-Null (rtx5070_env) PS E:\PyTorch_Build\pytorch> Copy-Item $PROFILE $backupDir -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> Copy-Item "$env:USERPROFILE\Documents\WindowsPowerShell" $backupDir -Recurse -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 2. 删除问题配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item $PROFILE -Force -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item "$env:USERPROFILE\Documents\WindowsPowerShell" -Recurse -Force -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 3. 创建新的配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $newProfileContent = @' >> # 新版配置文件 >> Write-Host "PowerShell 配置文件已重置" -ForegroundColor Cyan >> '@ (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-Content $PROFILE $newProfileContent -Force Set-Content : 未能找到路径“C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”的一部分。 所在位置 行:1 字符: 1 + Set-Content $PROFILE $newProfileContent -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Admini...ell_profile.ps1:String) [Set-Content], DirectoryNotFo undException + FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands.SetContentCommand (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 4. 重置执行策略 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-ExecutionPolicy Undefined -Scope CurrentUser -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 5. 重启 PowerShell (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "请关闭所有 PowerShell 窗口并重新打开" -ForegroundColor Yellow 请关闭所有 PowerShell 窗口并重新打开 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 1. 验证执行策略 (rtx5070_env) PS E:\PyTorch_Build\pytorch> if ((Get-ExecutionPolicy) -ne "RemoteSigned") { >> Write-Host "❌ 执行策略验证失败" -ForegroundColor Red >> exit 1 >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 2. 验证安全模块 (rtx5070_env) PS E:\PyTorch_Build\pytorch> try { >> $module = Import-Module Microsoft.PowerShell.Security -PassThru -ErrorAction Stop >> Write-Host "✅ 安全模块已加载 (版本: $($module.Version))" -ForegroundColor Green >> } >> catch { >> Write-Host "❌ 安全模块加载失败: $_" -ForegroundColor Red >> exit 2 >> } ✅ 安全模块已加载 (版本: 3.0.0.0) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 3. 验证WSL状态 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $wslStatus = wsl --status 2>&1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> if ($wslStatus -match "默认分发") { >> Write-Host "✅ WSL 状态正常" -ForegroundColor Green >> } else { >> Write-Host "⚠️ WSL 状态异常: $wslStatus" -ForegroundColor Yellow >> } ⚠️ WSL 状态异常: *g�[ň�(u�N Linux �v Windows P[�|�~0�S␦�ǏЏL� wsl.exe --install ۏL��[ň0 gsQ��~�Oo` ������ https://aka.ms/wslinstall (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 4. 验证配置文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (Test-Path $PROFILE) { >> Write-Host "✅ 配置文件存在: $PROFILE" -ForegroundColor Green >> Get-Content $PROFILE | Select-Object -First 5 >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch>
09-03
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源代码杀手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值