PowerShell 7 环境已加载 (版本: 7.5.2) PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> # 实时监控工具 PS C:\Users\Administrator\Desktop> choco install hwinfo -y choco: The term 'choco' 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. PS C:\Users\Administrator\Desktop> Start-Process "hwinfo64.exe" -ArgumentList "/sensors" Start-Process: This command cannot be run due to the error: An error occurred trying to start process 'hwinfo64.exe' with working directory 'C:\Users\Administrator\Desktop'. 系统找不到指定的文件。 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 性能计数器 PS C:\Users\Administrator\Desktop> Get-Counter -Counter "\Processor(*)\% Processor Time" -Continuous | >> ForEach-Object { >> $_.CounterSamples | >> Where-Object InstanceName -notmatch "_Total" | >> Sort-Object CookedValue -Descending | >> Select-Object -First 5 >> }

时间: 2025-09-01 21:56:44 AIGC 浏览: 22
<think> 我们遇到了两个问题: 1. `choco` 命令不可用,说明 Chocolatey 包管理器未安装或未添加到 PATH。 2. `hwinfo64.exe` 未安装,因此无法启动。 解决方案: 1. 安装 Chocolatey(如果尚未安装)。 2. 使用 Chocolatey 安装 HWInfo。 3. 然后运行 HWInfo 和性能计数器。 ### 安装 Chocolatey 在 PowerShell 7 中,我们需要以管理员身份运行以下命令来安装 Chocolatey。 ```powershell # 设置执行策略(可能需要管理员权限) Set-ExecutionPolicy Bypass -Scope Process -Force # 安装 Chocolatey [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) # 验证安装 choco --version ``` ### 安装 HWInfo ```powershell # 使用 Chocolatey 安装 HWInfo choco install hwinfo -y ``` ### 运行 HWInfo 并监控性能 安装完成后,我们可以运行 HWInfo 并同时监控性能计数器。 ```powershell # 启动 HWInfo 传感器 Start-Process "hwinfo64.exe" -ArgumentList "/sensors" # 同时运行性能计数器(按 Ctrl+C 终止) Get-Counter -Counter "\Processor(*)\% Processor Time" -Continuous | ForEach-Object { Clear-Host $topProcessors = $_.CounterSamples | Where-Object InstanceName -notmatch "_Total" | Sort-Object CookedValue -Descending | Select-Object -First 5 $topProcessors | Format-Table -AutoSize Start-Sleep -Seconds 2 } ``` ### 代码说明 1. **安装 Chocolatey**: - 首先确保可以执行远程脚本(设置执行策略)。 - 下载并运行 Chocolatey 安装脚本。 2. **安装 HWInfo**: - 使用 `choco install` 命令安装 HWInfo,`-y` 表示自动确认。 3. **启动 HWInfo**: - 使用 `Start-Process` 启动 `hwinfo64.exe` 并传递参数 `/sensors` 以显示传感器信息。 4. **性能计数器**: - 使用 `Get-Counter` 连续获取处理器时间计数器。 - 过滤掉“_Total”实例,并按使用率排序,取前5个。 - 每2秒刷新一次,并清屏显示(使用 `Clear-Host`)。 ### 注意事项 - 运行安装 Chocolatey 的脚本需要管理员权限。 - HWInfo 安装后,可能需要重新启动 PowerShell 会话才能从任何路径访问 `hwinfo64.exe`。或者,我们可以使用完整路径:`C:\Program Files\HWiNFO64\hwinfo64.exe`。 ### 完整脚本 以下是完整的脚本,包括错误处理: ```powershell # 检查 Chocolatey 是否安装 if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { Write-Host "正在安装 Chocolatey..." Set-ExecutionPolicy Bypass -Scope Process -Force [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-RestMethod https://community.chocolatey.org/install.ps1 | Invoke-Expression } # 检查 HWInfo 是否安装 if (-not (Get-Command hwinfo64.exe -ErrorAction SilentlyContinue)) { Write-Host "正在安装 HWInfo..." choco install hwinfo -y } # 启动 HWInfo 传感器 Write-Host "启动 HWInfo 传感器..." Start-Process "hwinfo64.exe" -ArgumentList "/sensors" # 运行性能计数器 Write-Host "开始监控 CPU 使用率(按 Ctrl+C 退出)..." try { Get-Counter -Counter "\Processor(*)\% Processor Time" -Continuous | ForEach-Object { Clear-Host $topProcessors = $_.CounterSamples | Where-Object { $_.InstanceName -notmatch "_Total|Idle" } | Sort-Object CookedValue -Descending | Select-Object -First 5 $topProcessors | Format-Table -Property InstanceName, @{Name="Usage %"; Expression={[math]::Round($_.CookedValue,2)}} -AutoSize Start-Sleep -Seconds 2 } } catch { Write-Host "监控已终止。" } ``` ### 相关问题 以上代码解决了当前问题,并提供了硬件监控的解决方案。 §§相关问题§§: 1. 如何在PowerShell中捕获并处理外部进程的输出? 2. 如何在没有管理员权限的情况下安装软件? 3. 如何使用PowerShell监控GPU温度? 4. PowerShell中如何实现定时任务(计划任务)? </think> 根据您的反馈,我注意到两个核心问题:Chocolatey未安装以及HWInfo工具缺失。以下是完整的解决方案和优化后的监控脚本: ### 修复依赖问题的完整方案 #### 1. 安装Chocolatey包管理器(系统级) ```powershell # 以管理员身份运行此脚本 Set-ExecutionPolicy Bypass -Scope Process -Force [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-RestMethod https://community.chocolatey.org/install.ps1 | Invoke-Expression # 验证安装 choco --version ``` #### 2. 安装系统监控工具 ```powershell # 安装HWInfo(硬件监控) choco install hwinfo -y --ignore-checksums # 安装OpenHardwareMonitor(替代方案) choco install openhardwaremonitor -y # 安装PSWindowsUpdate(用于Windows更新管理) Install-Module -Name PSWindowsUpdate -Force Import-Module PSWindowsUpdate ``` ### 优化后的硬件监控脚本 ```powershell # ======== 硬件监控模块 ======== function Get-RealTimeSystemMetrics { param( [int]$RefreshInterval = 2 # 刷新间隔(秒) ) # 检测可用监控工具 $monitorTool = if (Get-Command hwinfo64.exe -ErrorAction SilentlyContinue) { "hwinfo64 /sensors" } elseif (Get-Command OpenHardwareMonitor.exe -ErrorAction SilentlyContinue) { "OpenHardwareMonitor" } else { "BuiltIn" } # 初始化计数器 $cpuCounters = @("\Processor(*)\% Processor Time") $memCounters = @("\Memory\Available MBytes", "\Memory\% Committed Bytes In Use") $diskCounters = @("\PhysicalDisk(*)\% Disk Time", "\PhysicalDisk(*)\Disk Bytes/sec") $gpuCounters = @("\GPU Engine(*)\Utilization Percentage") # 主监控循环 while ($true) { $metrics = @{} # CPU监控 $cpuData = Get-Counter -Counter $cpuCounters -ErrorAction SilentlyContinue $metrics.CPU = $cpuData.CounterSamples | Where-Object { $_.InstanceName -notmatch "_Total|Idle" } | Sort-Object CookedValue -Descending | Select-Object -First 5 | ForEach-Object { [PSCustomObject]@{ Core = $_.InstanceName.Replace('processor(', '').Replace(')', '') Usage = [math]::Round($_.CookedValue, 1) } } # 内存监控 $memData = Get-Counter -Counter $memCounters $metrics.Memory = [PSCustomObject]@{ AvailableMB = [math]::Round(($memData.CounterSamples | Where-Object Path -match "Available MBytes").CookedValue) UsagePercent = [math]::Round(($memData.CounterSamples | Where-Object Path -match "% Committed").CookedValue, 1) } # GPU监控(需要管理员权限) try { $gpuData = Get-Counter -Counter $gpuCounters -ErrorAction Stop $metrics.GPU = $gpuData.CounterSamples | Group-Object { ($_.InstanceName -split "\\")[0] } | Sort-Object { $_.Group.CookedValue | Measure-Object -Sum | Select-Object -ExpandProperty Sum } -Descending | Select-Object -First 1 | ForEach-Object { [PSCustomObject]@{ Name = $_.Name Usage = [math]::Round(($_.Group.CookedValue | Measure-Object -Sum).Sum, 1) } } } catch { $metrics.GPU = [PSCustomObject]@{ Name = "N/A"; Usage = "Requires Admin" } } # 显示监控面板 Clear-Host Write-Host "=== 实时系统监控 (刷新间隔: ${RefreshInterval}s) ===" -ForegroundColor Cyan Write-Host "监控工具: $monitorTool`n" Write-Host "CPU 使用率 (Top 5核心):" -ForegroundColor Yellow $metrics.CPU | Format-Table @{Name="核心";Expression={$_.Core}}, @{Name="使用率(%)";Expression={$_.Usage}} -AutoSize Write-Host "`n内存状态:" -ForegroundColor Yellow Write-Host "可用内存: $($metrics.Memory.AvailableMB) MB" Write-Host "使用率: $($metrics.Memory.UsagePercent)%`n" Write-Host "GPU 状态:" -ForegroundColor Yellow $metrics.GPU | Format-Table Name, @{Name="使用率(%)";Expression={$_.Usage}} -AutoSize # 温度监控(如果工具可用) if ($monitorTool -ne "BuiltIn") { Write-Host "`n温度监控:" -ForegroundColor Yellow if ($monitorTool -match "hwinfo") { Start-Process hwinfo64.exe -ArgumentList "/sensors" -NoNewWindow -Wait } else { Start-Process OpenHardwareMonitor.exe -NoNewWindow } } Start-Sleep -Seconds $RefreshInterval } } # 启动监控(按Ctrl+C退出) Get-RealTimeSystemMetrics -RefreshInterval 3 ``` ### 关键优化点说明: 1. **多工具兼容性**: ```powershell $monitorTool = if (Get-Command hwinfo64.exe...) ``` - 自动检测可用监控工具,优先使用HWInfo,其次使用OpenHardwareMonitor - 无工具时回退到系统内置计数器 2. **GPU监控增强**: ```powershell $gpuCounters = @("\GPU Engine(*)\Utilization Percentage") ``` - 使用WMI性能计数器获取GPU利用率 - 需要管理员权限获取完整数据 3. **实时显示优化**: ```powershell Clear-Host $metrics.CPU | Format-Table... ``` - 每3秒清屏刷新数据 - 表格化显示核心利用率排名 - 突出显示关键指标 4. **错误处理机制**: ```powershell try {...} catch { $metrics.GPU = ... } ``` - 优雅处理权限不足问题 - 提供明确的错误提示 ### 管理员权限解决方案: ```powershell # 创建快捷方式以管理员身份运行 $shortcutPath = "$env:USERPROFILE\Desktop\SystemMonitor.lnk" $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut($shortcutPath) $shortcut.TargetPath = "pwsh.exe" $shortcut.Arguments = "-NoExit -Command `"& '$PSCommandPath'`"" $shortcut.WorkingDirectory = $PWD.Path $shortcut.Save() # 设置管理员权限 $bytes = [System.IO.File]::ReadAllBytes($shortcutPath) $bytes[0x15] = $bytes[0x15] -bor 0x20 [System.IO.File]::WriteAllBytes($shortcutPath, $bytes) ``` ### 注意事项: 1. 完整GPU监控需要: ```powershell Set-ExecutionPolicy RemoteSigned -Scope CurrentUser ``` 2. 首次运行可能提示: ```powershell Set-MpPreference -DisableRealtimeMonitoring $true -Force ``` 临时禁用实时防护
阅读全文

相关推荐

PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> # 定位到问题行号 PS C:\Users\Administrator\Desktop> $filePath = "E:\PyTorch_Build\pytorch\CMakeLists.txt" PS C:\Users\Administrator\Desktop> $content = Get-Content $filePath PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 替换问题代码 PS C:\Users\Administrator\Desktop> $newContent = $content -replace >> 'if \(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"\)', >> 'if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" AND NOT WIN32)' PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> Set-Content $filePath $newContent PS C:\Users\Administrator\Desktop> # 获取 CUDA 路径的短名称 PS C:\Users\Administrator\Desktop> $cudaPath = "E:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0" PS C:\Users\Administrator\Desktop> $shortPath = cmd /c "for %A in ('$cudaPath') do @echo %~sA" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 更新 CMake 参数 PS C:\Users\Administrator\Desktop> $cmakeArgs = @( >> "-DCUDNN_LIBRARY='$shortPath\lib\x64\cudnn.lib'", >> "-DCUDNN_INCLUDE_DIR='$shortPath\include'" >> ) PS C:\Users\Administrator\Desktop> # 确保 OPENBLAS_HOME 环境变量已设置 PS C:\Users\Administrator\Desktop> $env:OPENBLAS_HOME = "E:\OpenBLAS" # 替换为实际路径 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 编译完成后恢复 PS C:\Users\Administrator\Desktop> # [System.Console]::OutputEncoding = $oldCP PS C:\Users\Administrator\Desktop>

小蓝窗:“PS C:\Users\Administrator> # 1. 确保已创建配置文件 PS C:\Users\Administrator> if (!(Test-Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force } PS C:\Users\Administrator> PS C:\Users\Administrator> # 2. 打开配置文件进行编辑 PS C:\Users\Administrator> notepad $PROFILE PS C:\Users\Administrator> # 重新加载配置文件 PS C:\Users\Administrator> . $PROFILE PS C:\Users\Administrator> PS C:\Users\Administrator> # 检查模块是否加载 PS C:\Users\Administrator> Get-Module CurlTools PS C:\Users\Administrator> PS C:\Users\Administrator> # 检查模块路径 PS C:\Users\Administrator> $env:PSModulePath -split ';' | Where-Object { $_ -eq "E:\CurlTools\Modules" } E:\CurlTools\Modules E:\CurlTools\Modules PS C:\Users\Administrator> PS C:\Users\Administrator> # 测试模块功能(如果模块有命令) PS C:\Users\Administrator> Get-Command -Module CurlTools PS C:\Users\Administrator> PS C:\Users\Administrator> # 检查模块是否加载(应有输出) PS C:\Users\Administrator> Get-Module CurlTools PS C:\Users\Administrator> PS C:\Users\Administrator> # 检查中文是否正常显示(应无乱码) PS C:\Users\Administrator> "中文测试" 中文测试 PS C:\Users\Administrator> PS C:\Users\Administrator> # 检查别名是否设置 PS C:\Users\Administrator> Get-Alias ps7 CommandType Name Version Source ----------- ---- ------- ------ Alias ps7 -> Start-PS7 PS C:\Users\Administrator> PS C:\Users\Administrator> # 启动PowerShell 7 PS C:\Users\Administrator> ps7 PowerShell 7.5.2 PS C:\Users\Administrator> PS C:\Users\Administrator>” 我现在应该做什么

PowerShell 7 环境已加载 (版本: 7.5.2) PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> # 运行此脚本检查环境问题 PS C:\Users\Administrator\Desktop> $envReport = @() PS C:\Users\Administrator\Desktop> $envReport += "Powershell版本: $($PSVersionTable.PSVersion)" PS C:\Users\Administrator\Desktop> $envReport += "CMake版本: $(cmake --version | Select-String 'version')" PS C:\Users\Administrator\Desktop> $envReport += "Visual Studio路径: $(Get-Command msbuild | Select-Object -ExpandProperty Source)" Get-Command: The term 'msbuild' 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. PS C:\Users\Administrator\Desktop> $envReport += "PATH环境变量: $($env:PATH -replace ';', "n")" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 检查Libuv源码完整性 PS C:\Users\Administrator\Desktop> $libuvDir = "E:\PyTorch_Build\third_party\libuv" PS C:\Users\Administrator\Desktop> $requiredFiles = @("CMakeLists.txt", "include/uv.h", "src/win/winapi.c") PS C:\Users\Administrator\Desktop> foreach ($file in $requiredFiles) { >> $fullPath = Join-Path $libuvDir $file >> $envReport += "$file exists: $(Test-Path $fullPath)" >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> $envReport | Out-File "PyTorch_Build_Diagnostic.txt" PS C:\Users\Administrator\Desktop> Write-Host "✅ 环境诊断报告已保存到 PyTorch_Build_Diagnostic.txt" ✅ 环境诊断报告已保存到 PyTorch_Build_Diagnostic.txt PS C:\Users\Administrator\Desktop> import torch import: The term 'import' 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. PS C:\Users\Administrator\Desktop> print(torch.__version__) # 应显示本地编译版本 torch.__version__: The term 'torch.__version__' 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. PS C:\Users\Administrator\Desktop> print(torch.cuda.is_available()) # 必须返回True ParserError: Line | 1 | print(torch.cuda.is_available()) # 必须返回True | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> # 测试GPU加速 PS C:\Users\Administrator\Desktop> tensor = torch.randn(10000, 10000).cuda() InvalidOperation: Method invocation failed because [System.Int32] does not contain a method named 'cuda'. PS C:\Users\Administrator\Desktop> %timeit tensor @ tensor.T ParserError: Line | 1 | %timeit tensor @ tensor.T | ~ | Unrecognized token in source text. PS C:\Users\Administrator\Desktop>

PS C:\Users\Administrator\Desktop> # 检查 PowerShell 7 安装状态 PS C:\Users\Administrator\Desktop> $pwshPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> if (-not (Test-Path $pwshPath)) { >> Write-Host "PowerShell 7 未安装,正在自动安装..." -ForegroundColor Yellow >> >> # 下载安装包 >> $url = "https://github.com/PowerShell/PowerShell/releases/download/v7.3.6/PowerShell-7.3.6-win-x64.msi" >> $output = "$env:TEMP\PowerShell-7.3.6-win-x64.msi" >> >> try { >> Invoke-WebRequest -Uri $url -OutFile $output -ErrorAction Stop >> Write-Host "下载完成,开始安装..." -ForegroundColor Green >> } >> catch { >> Write-Host "下载失败: $_" -ForegroundColor Red >> return >> } >> >> # 静默安装 >> Start-Process msiexec.exe -ArgumentList "/i "$output" /qn" -Wait >> Remove-Item $output -Force >> >> # 验证安装 >> if (Test-Path $pwshPath) { >> Write-Host "PowerShell 7 安装成功!" -ForegroundColor Green >> } else { >> Write-Host "安装失败,请手动安装" -ForegroundColor Red >> Write-Host "下载地址: https://aka.ms/install-powershell" -ForegroundColor Cyan >> } >> } else { >> Write-Host "PowerShell 7 已安装" -ForegroundColor Green >> } PowerShell 7 未安装,正在自动安装... 下载完成,开始安装... PowerShell 7 安装成功! PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 启动 PowerShell 7 PS C:\Users\Administrator\Desktop> & $pwshPath -NoExit -Command { >> Write-Host "=== PowerShell 7 环境 ===" -ForegroundColor Cyan >> $PSVersionTable >> } PowerShell 7 环境已加载 (版本: 7.3.6) === PowerShell 7 环境 === Name Value ---- ----- PSVersion 7.3.6 PSEdition Core GitCommitId 7.3.6 OS Microsoft Windows 10.0.26100 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 PS C:\Users\Administrator\Desktop> # 创建 PowerShell 7 专用配置文件 PS C:\Users\Administrator\Desktop> $pwshProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> @' >> # 启用现代语法 >> Set-StrictMode -Version 3.0 >> >> # 自定义函数 >> function Invoke-Analyzer { >> if (Test-Path "E:\DesktopAnalyzer.ps1") { >> & "E:\DesktopAnalyzer.ps1" >> } else { >> Write-Host "错误: DesktopAnalyzer.ps1 不存在" -ForegroundColor Red >> } >> } >> >> function Invoke-Verifier { >> if (Test-Path "E:\PythonEnvVerifier.ps1") { >> & "E:\PythonEnvVerifier.ps1" >> } else { >> Write-Host "错误: PythonEnvVerifier.ps1 不存在" -ForegroundColor Red >> } >> } >> >> function Clean-Desktop { >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> $items = @("myenv", "PythonTools", "path_diagnostic.py", "PythonEnvRepair*") >> >> $removedCount = 0 >> foreach ($item in $items) { >> $path = Join-Path $desktopPath $item >> if (Test-Path $path) { >> Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue >> $removedCount++ >> } >> } >> >> Write-Host "清理完成: 已删除 $removedCount 个项目" -ForegroundColor Green >> } >> >> # 别名设置 >> Set-Alias da Invoke-Analyzer >> Set-Alias ve Invoke-Verifier >> Set-Alias clean Clean-Desktop >> >> # 提示信息 >> Write-Host "PowerShell 7 环境已加载 (版本: $($PSVersionTable.PSVersion))" -ForegroundColor Cyan >> '@ | Set-Content -Path $pwshProfile -Encoding UTF8 PS C:\Users\Administrator\Desktop> # 在 PowerShell 7 会话中运行以下命令 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 三元运算符 PS C:\Users\Administrator\Desktop> $result = "成功" PS C:\Users\Administrator\Desktop> Write-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' : 'Red') 检测结果: 成功 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 空值合并运算符 PS C:\Users\Administrator\Desktop> $envVar = $null PS C:\Users\Administrator\Desktop> Write-Host "PYTHONPATH: $($envVar ?? '未设置')" PYTHONPATH: 未设置 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 类定义(修正版) PS C:\Users\Administrator\Desktop> class FileInfo { >> [string]$Name >> [datetime]$Modified >> [double]$SizeKB >> >> FileInfo([System.IO.FileInfo]$file) { >> $this.Name = $file.Name >> $this.Modified = $file.LastWriteTime >> $this.SizeKB = [math]::Round($file.Length / 1KB, 2) >> } >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 使用类 PS C:\Users\Administrator\Desktop> $files = Get-ChildItem | Where-Object { -not $_.PSIsContainer } | ForEach-Object { >> [FileInfo]::new($_) >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> $files | Format-Table Name, Modified, SizeKB Name Modified SizeKB ---- -------- ------ 此电脑.lnk 2025/8/19 18:08:37 0.38 底特律:化身为人.url 2025/8/19 19:59:30 0.22 黑神话:悟空.url 2025/8/19 19:27:24 0.22 AI工作区.url 2025/8/5 0:16:22 0.10 PowerShell 7.lnk 2025/8/23 1:27:37 1.83 Repair-PythonSite.ps1 2025/8/22 19:39:27 0.10 requirements.txt 2025/8/22 0:28:04 4.92 test_module.py 2025/8/23 0:10:27 0.04 UTF8_PowerShell.lnk 2025/8/22 19:38:41 1.10 verify_path.py 2025/8/23 0:27:23 0.25 Windows PowerShell.lnk 2025/8/21 22:12:59 2.12 PS C:\Users\Administrator\Desktop> # 创建虚拟环境 PS C:\Users\Administrator\Desktop> python -m venv "E:\PythonTools\clean_env" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 激活虚拟环境 PS C:\Users\Administrator\Desktop> . "E:\PythonTools\clean_env\Scripts\Activate.ps1" (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 检查 Python 路径(Windows 正确方式) (clean_env) PS C:\Users\Administrator\Desktop> Write-Host "当前Python: $(Get-Command python | Select-Object -ExpandProperty Source)" 当前Python: E:\PythonTools\clean_env\Scripts\python.exe (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 安装依赖 (clean_env) PS C:\Users\Administrator\Desktop> pip install -r "E:\requirements.txt" Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: flask>=2.0.0 in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 2)) (3.1.2) Requirement already satisfied: python-dotenv in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 3)) (1.1.1) Requirement already satisfied: psutil in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 4)) (7.0.0) Requirement already satisfied: sqlalchemy in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 5)) (2.0.43) Requirement already satisfied: requests in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 6)) (2.32.5) Requirement already satisfied: flask-sse in e:\pythontools\clean_env\lib\site-packages (from -r E:\requirements.txt (line 7)) (1.0.0) Requirement already satisfied: jinja2>=3.1.2 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (3.1.6) Requirement already satisfied: click>=8.1.3 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (8.2.1) Requirement already satisfied: werkzeug>=3.1.0 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (3.1.3) Requirement already satisfied: itsdangerous>=2.2.0 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (2.2.0) Requirement already satisfied: markupsafe>=2.1.1 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (3.0.2) Requirement already satisfied: blinker>=1.9.0 in e:\pythontools\clean_env\lib\site-packages (from flask>=2.0.0->-r E:\requirements.txt (line 2)) (1.9.0) Requirement already satisfied: typing-extensions>=4.6.0 in e:\pythontools\clean_env\lib\site-packages (from sqlalchemy->-r E:\requirements.txt (line 5)) (4.14.1) Requirement already satisfied: greenlet>=1 in e:\pythontools\clean_env\lib\site-packages (from sqlalchemy->-r E:\requirements.txt (line 5)) (3.2.4) Requirement already satisfied: certifi>=2017.4.17 in e:\pythontools\clean_env\lib\site-packages (from requests->-r E:\requirements.txt (line 6)) (2025.8.3) Requirement already satisfied: charset_normalizer<4,>=2 in e:\pythontools\clean_env\lib\site-packages (from requests->-r E:\requirements.txt (line 6)) (3.4.3) Requirement already satisfied: idna<4,>=2.5 in e:\pythontools\clean_env\lib\site-packages (from requests->-r E:\requirements.txt (line 6)) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in e:\pythontools\clean_env\lib\site-packages (from requests->-r E:\requirements.txt (line 6)) (2.5.0) Requirement already satisfied: redis in e:\pythontools\clean_env\lib\site-packages (from flask-sse->-r E:\requirements.txt (line 7)) (6.4.0) Requirement already satisfied: six in e:\pythontools\clean_env\lib\site-packages (from flask-sse->-r E:\requirements.txt (line 7)) (1.17.0) Requirement already satisfied: colorama in e:\pythontools\clean_env\lib\site-packages (from click>=8.1.3->flask>=2.0.0->-r E:\requirements.txt (line 2)) (0.4.6) Requirement already satisfied: async-timeout>=4.0.3 in e:\pythontools\clean_env\lib\site-packages (from redis->flask-sse->-r E:\requirements.txt (line 7)) (5.0.1) [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 运行脚本(确保文件存在) (clean_env) PS C:\Users\Administrator\Desktop> if (Test-Path "E:\verify_path.py") { >> python "E:\verify_path.py" >> } else { >> Write-Host "警告: verify_path.py 不存在" -ForegroundColor Yellow >> } 警告: verify_path.py 不存在 (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 停用虚拟环境 (clean_env) PS C:\Users\Administrator\Desktop> deactivate PS C:\Users\Administrator\Desktop> # 保存为 E:\Setup-PowerShell7.ps1 PS C:\Users\Administrator\Desktop> param( >> [switch]$Install, >> [switch]$Configure >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 安装 PowerShell 7 PS C:\Users\Administrator\Desktop> if ($Install) { >> $url = "https://github.com/PowerShell/PowerShell/releases/download/v7.3.6/PowerShell-7.3.6-win-x64.msi" >> $output = "$env:TEMP\PowerShell-7.3.6-win-x64.msi" >> >> try { >> Invoke-WebRequest -Uri $url -OutFile $output -ErrorAction Stop >> Start-Process msiexec.exe -ArgumentList "/i "$output" /qn" -Wait >> Remove-Item $output -Force -ErrorAction SilentlyContinue >> Write-Host "PowerShell 7 安装成功" -ForegroundColor Green >> } >> catch { >> Write-Host "安装失败: $_" -ForegroundColor Red >> } >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 配置环境 PS C:\Users\Administrator\Desktop> if ($Configure) { >> # 创建配置文件 >> $pwshProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" >> @' >> # 配置文件内容(如前所述) >> '@ | Set-Content -Path $pwshProfile -Encoding UTF8 >> >> # 创建快捷方式 >> $shortcutPath = "$env:USERPROFILE\Desktop\PowerShell 7.lnk" >> $WshShell = New-Object -ComObject WScript.Shell >> $shortcut = $WshShell.CreateShortcut($shortcutPath) >> $shortcut.TargetPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" >> $shortcut.Arguments = "-NoExit" >> $shortcut.Save() >> >> Write-Host "PowerShell 7 环境配置完成!" -ForegroundColor Green >> Write-Host "请使用桌面上的 'PowerShell 7' 快捷方式启动" -ForegroundColor Yellow >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 使用示例: PS C:\Users\Administrator\Desktop> # 在 PowerShell 7 中运行: PS C:\Users\Administrator\Desktop> # & "E:\Setup-PowerShell7.ps1" -Install -Configure PS C:\Users\Administrator\Desktop> # 在 Windows PowerShell 中运行 PS C:\Users\Administrator\Desktop> & "E:\Setup-PowerShell7.ps1" -Install -Configure &: The term 'E:\Setup-PowerShell7.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. PS C:\Users\Administrator\Desktop> da # 运行桌面分析 PS C:\Users\Administrator\Desktop> ve # 运行环境验证 PS C:\Users\Administrator\Desktop> clean # 清理桌面 >> # 创建并激活环境 ParserError: Line | 1 | clean # 清理桌面 | ~ | Missing statement block after 'clean'. PS C:\Users\Administrator\Desktop> python -m venv "E:\myenv" PS C:\Users\Administrator\Desktop> . "E:\myenv\Scripts\Activate.ps1" (myenv) PS C:\Users\Administrator\Desktop> (myenv) PS C:\Users\Administrator\Desktop> # 在虚拟环境中工作 (myenv) PS C:\Users\Administrator\Desktop> pip install pandas Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: pandas in e:\myenv\lib\site-packages (2.3.2) Requirement already satisfied: pytz>=2020.1 in e:\myenv\lib\site-packages (from pandas) (2025.2) Requirement already satisfied: python-dateutil>=2.8.2 in e:\myenv\lib\site-packages (from pandas) (2.9.0.post0) Requirement already satisfied: tzdata>=2022.7 in e:\myenv\lib\site-packages (from pandas) (2025.2) Requirement already satisfied: numpy>=1.22.4 in e:\myenv\lib\site-packages (from pandas) (2.2.6) Requirement already satisfied: six>=1.5 in e:\myenv\lib\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0) [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (myenv) PS C:\Users\Administrator\Desktop> python "E:\myscript.py" E:\Python310\python.exe: can't open file 'E:\\myscript.py': [Errno 2] No such file or directory (myenv) PS C:\Users\Administrator\Desktop> (myenv) PS C:\Users\Administrator\Desktop> # 退出环境 (myenv) PS C:\Users\Administrator\Desktop> deactivate PS C:\Users\Administrator\Desktop> # 1. 启动 PowerShell 7 PS C:\Users\Administrator\Desktop> & "$env:ProgramFiles\PowerShell\7\pwsh.exe" PowerShell 7.3.6 A new PowerShell stable release is available: v7.5.2 Upgrade now, or check out the release page at: https://aka.ms/PowerShell-Release?tag=v7.5.2 PowerShell 7 环境已加载 (版本: 7.3.6) PS C:\Users\Administrator\Desktop>

PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> # 初始化 cmakeArgs 数组 PS C:\Users\Administrator\Desktop> $cmakeArgs = @( "} >> "-G", "Ninja", >> "-DCMAKE_BUILD_TYPE=Release", >> "-DCMAKE_C_COMPILER=cl.exe", >> "-DCMAKE_CXX_COMPILER=cl.exe", >> "-DBUILD_PYTHON=ON", >> "-DUSE_CUDA=ON", >> "-DCUDA_TOOLKIT_ROOT_DIR='E:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0'" >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 初始化其他必要变量 PS C:\Users\Administrator\Desktop> $oldCP = $null PS C:\Users\Administrator\Desktop> $fixScript = $null PS C:\Users\Administrator\Desktop> # 获取 CUDA 短路径 PS C:\Users\Administrator\Desktop> $cudaPath = "E:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0" PS C:\Users\Administrator\Desktop> $shortPath = cmd /c "for %A in ('$cudaPath') do @echo %~sA" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 添加 cuDNN 配置 PS C:\Users\Administrator\Desktop> $cmakeArgs += @( >> "-DCUDNN_LIBRARY='$shortPath\lib\x64\cudnn.lib'", >> "-DCUDNN_INCLUDE_DIR='$shortPath\include'" >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 添加 OpenBLAS 配置 PS C:\Users\Administrator\Desktop> $env:OPENBLAS_HOME = "E:\OpenBLAS" PS C:\Users\Administrator\Desktop> $cmakeArgs += @( >> "-DOPENBLAS_LIBRARY='$env:OPENBLAS_HOME\lib\openblas.lib'", >> "-DOPENBLAS_INCLUDE_DIR='$env:OPENBLAS_HOME\include'" >> ) PS C:\Users\Administrator\Desktop> # 创建修复脚本内容 PS C:\Users\Administrator\Desktop> $fixScript = @' >> Get-ChildItem "build\confu-deps\XNNPACK\CMakeFiles" -Recurse -Filter "flags.make" | >> ForEach-Object { >> $content = Get-Content $_.FullName >> $newContent = $content -replace '/O1', '/O2' >> Set-Content -Path $_.FullName -Value $newContent >> } >> '@ PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 保存为脚本文件 PS C:\Users\Administrator\Desktop> Set-Content -Path ".\fix_xnnpack_flags.ps1" -Value $fixScript PS C:\Users\Administrator\Desktop>

PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> # 强制删除旧虚拟环境(可能损坏) PS C:\Users\Administrator\Desktop> Remove-Item -Recurse -Force E:\PyTorch_Build\pytorch\rtx5070_env -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 使用系统Python创建新虚拟环境 PS C:\Users\Administrator\Desktop> $pythonPath = (Get-Command python).Source PS C:\Users\Administrator\Desktop> python -m venv --system-site-packages rtx5070_env PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 修复激活脚本权限(关键步骤) PS C:\Users\Administrator\Desktop> $activatePath = ".\rtx5070_env\Scripts\Activate.ps1" PS C:\Users\Administrator\Desktop> $acl = Get-Acl $activatePath PS C:\Users\Administrator\Desktop> $rule = New-Object System.Security.AccessControl.FileSystemAccessRule( >> "Users", "FullControl", "Allow" >> ) PS C:\Users\Administrator\Desktop> $acl.SetAccessRule($rule) PS C:\Users\Administrator\Desktop> Set-Acl -Path $activatePath -AclObject $acl PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 安全激活环境 PS C:\Users\Administrator\Desktop> $activation = @" >> try { >> & "$activatePath" >> Write-Host "✅ 虚拟环境激活成功" -ForegroundColor Green >> python -VV >> } >> catch { >> Write-Host "❌ 激活失败: $($_.Exception.Message)" -ForegroundColor Red >> } >> "@ InvalidOperation: Line | 8 | Write-Host "❌ 激活失败: $($_.Exception.Message)" -ForegroundColor … | ~~ | The variable '$_' cannot be retrieved because it has not been set. PS C:\Users\Administrator\Desktop> Invoke-Expression $activation ✅ 虚拟环境激活成功 Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] (rtx5070_env) PS C:\Users\Administrator\Desktop> (rtx5070_env) PS C:\Users\Administrator\Desktop> # 验证环境 (rtx5070_env) PS C:\Users\Administrator\Desktop> Write-Host "n环境状态验证:" -ForegroundColor Cyan 环境状态验证: (rtx5070_env) PS C:\Users\Administrator\Desktop> pip list | Select-String -Pattern "torch|cuda" torch 2.9.0a0+git2d31c3d E:\PyTorch_Build\pytorch torchaudio 2.5.0.dev20241112+cu121 torchvision 0.20.0.dev20241112+cu121 [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (rtx5070_env) PS C:\Users\Administrator\Desktop>

PowerShell 7 环境已加载 (版本: 7.3.6) PowerShell 7 环境已加载 (版本: 7.3.6) PS C:\Users\Administrator\Desktop> # 解决方案1:使用完整路径 PS C:\Users\Administrator\Desktop> & "E:\Setup-PowerShell7.ps1" -Install -Configure &: The term 'E:\Setup-PowerShell7.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. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 解决方案2:设置工作目录 PS C:\Users\Administrator\Desktop> Set-Location E:\ PS E:\> .\Setup-PowerShell7.ps1 -Install -Configure .\Setup-PowerShell7.ps1: The term '.\Setup-PowerShell7.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. PS E:\> # 重新加载配置文件 PS E:\> . $PROFILE PowerShell 7 环境已加载 (版本: 7.3.6) PS E:\> PS E:\> # 验证函数是否存在 PS E:\> Get-Command Clean-Desktop CommandType Name Version Source ----------- ---- ------- ------ Function Clean-Desktop PS E:\> # E:\myscript.py 示例内容 PS E:\> import sys import: The term 'import' 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. PS E:\> import os import: The term 'import' 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. PS E:\> PS E:\> print("=== Python 环境验证 ===") 无法初始化设备 PRN PS E:\> print(f"Python 路径: {sys.executable}") fPython 路径: {sys.executable}: The term 'fPython 路径: {sys.executable}' 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. PS E:\> print(f"工作目录: {os.getcwd()}") f工作目录: {os.getcwd()}: The term 'f工作目录: {os.getcwd()}' 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. PS E:\> print(f"环境变量 PATH: {os.environ.get('PATH', '')}") f环境变量 PATH: {os.environ.get('PATH', '')}: The term 'f环境变量 PATH: {os.environ.get('PATH', '')}' 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. PS E:\> # E:\Setup-PowerShell7.ps1 (最终修正版) PS E:\> param( >> [switch]$Install, >> [switch]$Configure >> ) PS E:\> PS E:\> # 安装 PowerShell 7 PS E:\> if ($Install) { >> $url = "https://github.com/PowerShell/PowerShell/releases/download/v7.5.2/PowerShell-7.5.2-win-x64.msi" >> $output = "$env:TEMP\PowerShell-7.5.2-win-x64.msi" >> >> try { >> Write-Host "下载 PowerShell 7.5.2..." -ForegroundColor Cyan >> Invoke-WebRequest -Uri $url -OutFile $output -ErrorAction Stop >> >> Write-Host "正在安装..." -ForegroundColor Yellow >> Start-Process msiexec.exe -ArgumentList "/i "$output" /qn" -Wait >> Remove-Item $output -Force -ErrorAction SilentlyContinue >> >> if (Test-Path "$env:ProgramFiles\PowerShell\7\pwsh.exe") { >> Write-Host "PowerShell 7 安装成功!" -ForegroundColor Green >> } else { >> Write-Host "安装失败,请手动安装" -ForegroundColor Red >> Write-Host "下载地址: https://aka.ms/install-powershell" -ForegroundColor Cyan >> } >> } >> catch { >> Write-Host "安装失败: $_" -ForegroundColor Red >> } >> } PS E:\> PS E:\> # 配置环境 PS E:\> if ($Configure) { >> # 创建配置文件目录 >> $profileDir = [System.IO.Path]::GetDirectoryName($PROFILE) >> if (-not (Test-Path $profileDir)) { >> New-Item -ItemType Directory -Path $profileDir -Force | Out-Null >> } >> >> # 配置文件内容 >> $profileContent = @' >> # 启用现代语法 >> Set-StrictMode -Version 3.0 >> >> # 自定义函数 >> function Invoke-Analyzer { >> if (Test-Path "E:\DesktopAnalyzer.ps1") { >> & "E:\DesktopAnalyzer.ps1" >> } else { >> Write-Host "错误: DesktopAnalyzer.ps1 不存在" -ForegroundColor Red >> @' >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> Write-Host "n=== 桌面文件分析 ===" -ForegroundColor Cyan >> Get-ChildItem $desktopPath | Format-Table Name, Length, LastWriteTime >> '@ | Set-Content "E:\DesktopAnalyzer.ps1" -Encoding UTF8 >> & "E:\DesktopAnalyzer.ps1" >> } PS E:\> } ParserError: Line | 1 | } | ~ | Unexpected token '}' in expression or statement. PS E:\> PS E:\> function Invoke-Verifier { >> if (Test-Path "E:\PythonEnvVerifier.ps1") { >> & "E:\PythonEnvVerifier.ps1" >> } else { >> Write-Host "错误: PythonEnvVerifier.ps1 不存在" -ForegroundColor Red >> @' >> Write-Host "n=== Python 环境验证 ===" -ForegroundColor Cyan >> python -c "import sys; print(f'Python 版本: {sys.version}')" >> pip --version >> '@ | Set-Content "E:\PythonEnvVerifier.ps1" -Encoding UTF8 >> & "E:\PythonEnvVerifier.ps1" >> } >> } PS E:\> PS E:\> function Clean-Desktop { >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> $items = @("myenv", "PythonTools", "path_diagnostic.py", "PythonEnvRepair*") >> >> $removedCount = 0 >> foreach ($item in $items) { >> $path = Join-Path $desktopPath $item >> if (Test-Path $path) { >> Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue >> $removedCount++ >> Write-Host "已删除: $path" -ForegroundColor Yellow >> } >> } >> >> Write-Host "清理完成: 已删除 $removedCount 个项目" -ForegroundColor Green >> } PS E:\> PS E:\> # 别名设置 PS E:\> Set-Alias da Invoke-Analyzer -Option AllScope PS E:\> Set-Alias ve Invoke-Verifier -Option AllScope PS E:\> Set-Alias clean Clean-Desktop -Option AllScope PS E:\> PS E:\> # 提示信息 PS E:\> Write-Host "PowerShell 7 环境已加载 (版本: $($PSVersionTable.PSVersion))" -ForegroundColor Cyan PowerShell 7 环境已加载 (版本: 7.3.6) PS E:\> '@ >> >> $profileContent | Set-Content -Path $PROFILE -Encoding UTF8 >> Write-Host "配置文件已创建: $PROFILE" -ForegroundColor Green >> >> # 创建桌面快捷方式 >> $shortcutPath = "$env:USERPROFILE\Desktop\PowerShell 7.lnk" >> $shell = New-Object -ComObject WScript.Shell >> $shortcut = $shell.CreateShortcut($shortcutPath) >> $shortcut.TargetPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" >> $shortcut.Arguments = "-NoExit -Command ". $PROFILE"" >> $shortcut.IconLocation = "$env:ProgramFiles\PowerShell\7\assets\Powershell_av_colors.ico" >> $shortcut.Save() >> >> Write-Host "桌面快捷方式已创建: $shortcutPath" -ForegroundColor Green >> Write-Host "环境配置完成!" -ForegroundColor Green >> } >> >> # 升级提示 >> if (($PSVersionTable.PSVersion -lt "7.5.0") -and (Test-Path "$env:ProgramFiles\PowerShell\7\pwsh.exe")) { >> Write-Host "n建议: 请升级到 PowerShell 7.5.2 以获得最新功能和安全更新" -ForegroundColor Yellow >> Write-Host "运行: & '$env:ProgramFiles\PowerShell\7\pwsh.exe' -Command { iwr -useb https://aka.ms/install-powershell.ps1 | iex }" -ForegroundColor Cyan >> } >> # 在 Windows PowerShell 中运行 >> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force >> & "E:\Setup-PowerShell7.ps1" -Install -Configure >> da # 运行桌面分析 >> ve # 运行环境验证 >> clean # 清理桌面 >> da # 运行桌面分析 >> ve # 运行环境验证 >> clean # 清理桌面 >> # 创建并激活环境 >> python -m venv "E:\myenv" >> . "E:\myenv\Scripts\Activate.ps1" >> >> # 安装包 >> pip install pandas numpy >> >> # 运行脚本 >> python "E:\myscript.py" >> >> # 退出环境 >> deactivate >>

最新推荐

recommend-type

智能体平台dify-1.13版本的sql表结构

https://github.com/langgenius 提供的docker版本,开源提供的sql有一些缺失,项目无法运行。 从docker拉出来的结构,已验证,1.13版本可部署运行。
recommend-type

【scratch3.0少儿编程-游戏原型-动画-项目源码】河道清理船巡线改编.zip

资源说明: 1:本资料仅用作交流学习参考,请切勿用于商业用途。 2:一套精品实用scratch3.0少儿编程游戏、动画源码资源,无论是入门练手还是项目复用都超实用,省去重复开发时间,让开发少走弯路! 更多精品资源请访问 https://blog.csdn.net/ashyyyy/article/details/146464041
recommend-type

具备建图导航人脸及异常行为检测功能的 ROS 安防机器人

打开下面链接,直接免费下载资源: https://renmaiwang.cn/s/i0hbr ROS 安防机器人系统,能够为用户提供包括建图导航、人脸识别以及异常行为检测在内的多项核心功能。
recommend-type

微信小程序基础实验项目_大学课程实践作业_微信开发者工具_前端开发_JavaScript_WXML_WXSS_小程序框架_组件应用_API调用_云开发_数据绑定_事件处理_页面路由.zip

微信小程序基础实验项目_大学课程实践作业_微信开发者工具_前端开发_JavaScript_WXML_WXSS_小程序框架_组件应用_API调用_云开发_数据绑定_事件处理_页面路由.zip
recommend-type

采用普通摄像头结合 dlib 与 opencv 实现人脸 68 点检测及识别

打开下面链接,直接免费下载资源: https://renmaiwang.cn/s/wverw 在对人的正面脸部展开识别工作的过程中,所运用的设备为常规类型的摄像头,同时,在技术应用层面,借助 dlib 工具来对人脸的 68 个特征点实施检测操作,并且利用 opencv 中的 FaceRecognizer 模块分别开展人脸模型的训练工作与后续的人脸识别工作。
recommend-type

Docker环境下的弹性APM服务器搭建指南

根据提供的文件信息,我们可以梳理出以下几个关键知识点: 1. Docker技术概念: Docker是一个开源的应用容器引擎,允许开发者打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何支持Docker的平台上。容器是完全使用沙箱机制,相互之间不会有任何接口(类似iOS的app)。 2. Docker的使用优势: 使用Docker部署应用可以带来多方面的优势,如提高开发效率、简化部署流程、易于迁移和扩展、强化安全性和隔离性等。容器化应用可以在不同的环境中保持一致的运行状态,减少了"在我的机器上可以运行"这类问题。 3. Compose工具: Docker Compose是一个用来定义和运行多容器Docker应用程序的工具。通过Compose,用户可以使用YAML文件来配置应用程序服务,并通过一个命令,完成容器的创建和启动。Docker Compose使得复杂配置的多容器应用的部署和管理工作变得简单。 4. APM(应用性能管理)服务器: APM服务器是用来监控和管理软件应用性能的工具。它通常包括实时性能监控、问题诊断、性能瓶颈定位、用户体验报告等功能。通过提供深入的应用性能洞察,APM能够帮助开发者和运维人员优化和提升应用性能。 5. 弹性APM服务器: 在标题中提到的“弹性”可能是指APM服务器能够根据应用的性能需求自动调整资源分配。这种弹性服务器可以动态地根据负载情况增加或减少资源,以保证应用性能的稳定,并在必要时节省资源。 6. Docker和Compose在APM服务器部署中的作用: Docker和Compose共同作用于APM服务器的部署,意味着开发者可能通过定义一个Docker Compose文件来指定APM服务器的所有依赖和服务。利用容器化的方式,可以保证APM服务器在开发、测试和生产环境中的部署和运行一致性。 7. “docker-apm-master”文件结构: 文件名称列表中提及的“docker-apm-master”很可能是包含Dockerfile、docker-compose.yml等文件的目录名称,这个目录用于管理和构建弹性APM服务器的Docker镜像和服务。在该目录下,可能包含了用于构建APM服务器镜像的脚本、配置文件,以及用于部署和管理APM服务器的Docker Compose配置。 8. 开发和运维实践: 一个“由Docker和Compose支持的弹性apm服务器”项目体现了现代软件开发和运维的实践,即使用容器化和自动化工具来提升开发效率、简化运维工作以及优化应用部署。在微服务架构和云计算日益普及的今天,这类实践变得越来越普遍。 综合以上知识点,我们可以理解“docker-apm:由Docker和Compose支持的弹性apm服务器”是一个运用现代开发运维技术实践,提供应用性能管理解决方案的项目。它结合了Docker容器化技术和Docker Compose自动化管理工具,以实现一个可扩展、弹性的APM服务器,帮助开发者和运维团队高效地监控和优化应用性能。
recommend-type

游戏开发与部署全流程指南

# 游戏开发与部署全流程指南 ## 1. 开发整体游戏结构 ### 1.1 场景添加与游戏启动 要确保场景能被加载,需将其添加到构建设置中。若不添加,Unity 就无法知晓可用的场景。在之前的测试中,若只是重新加载当前场景,无需进行此操作;但现在若要切换关卡,就必须添加。添加完成后,可从启动场景点击“播放”来启动游戏,此时游戏管理器对象会在两个场景中共享。 不过需注意,由于管理器是在启动场景中加载的,所以必须始终从该场景启动游戏。若觉得每次手动打开启动场景麻烦,可使用此编辑器脚本,它能在点击“播放”时自动切换到指定场景:[https://github.com/jhocking/from-u
recommend-type

初级运维面试题

<think> 首先,用户的问题是:“我想查找初级运维面试题”,这是在查询初级运维岗位的面试题。系统指令要求我参考提供的引用内容,这些引用来自之前的消息。 回顾引用内容: - 引用[1]:是关于运维面试题的文章,提到“2024年9月最新运维高频面试题汇总(1)”,但它是个标题,没有具体题目内容。它宣传了一个群组。 - 引用[2]:是“云计算运维工程师面试题(二)”,列出了11个具体问题,涉及云计算、弹性伸缩、高可用性、安全等。这些不是专门针对初级的,但可能涵盖。 - 引用[3]:是“初级运维工程师面试题”,描述了一个场景:查杀病毒的过程,提到了一个可疑进程。这不是直接的面试题列表,而是
recommend-type

构建Ikiwiki的Docker容器:简易部署与使用

### 知识点概述 #### 标题:“docker-ikiwiki:Ikiwiki的Docker容器” - Docker:一种开源的容器化平台,用于自动化部署、扩展和管理应用程序。 - Ikiwiki:一个使用git作为后端的wiki引擎,其特色在于使用Markdown或Textile等标记语言编辑页面。 - 容器化部署:利用Docker技术进行软件的打包、分发和运行,以容器形式提供一致的运行环境。 #### 描述:“Ikiwiki Docker容器” - Docker映像与使用:介绍了如何通过命令行工具拉取并运行一个Ikiwiki的Docker镜像。 - 拉取Docker镜像:使用命令`docker pull ankitrgadiya/ikiwiki`从Docker Hub中获取预配置好的Ikiwiki容器镜像。 - 使用方式:提供了两种使用该Docker镜像的示例,一种是与域名绑定进行SSL支持的配置,另一种是作为独立运行且不支持SSL的配置。 - 独立映像的局限性:明确指出独立映像不支持SSL,因此推荐与Nginx-Proxy结合使用以获得更好的网络服务。 #### 标签:“docker ikiwiki Shell” - 标签汇总:这些标签提示了该文档内容涉及的技术范畴,即Docker容器技术、Ikiwiki应用以及Shell命令行操作。 - Docker标签:强调了Docker在自动化部署Ikiwiki中的应用。 - Ikiwiki标签:指出了本文内容与Ikiwiki的使用和配置相关。 - Shell标签:表明操作过程涉及到Linux Shell命令的执行。 #### 压缩包子文件的文件名称列表:“docker-ikiwiki-master” - 压缩包内容:该列表暗示了压缩包内包含的文件是以"docker-ikiwiki-master"为名称的主目录或项目文件。 - 文件结构:可能包含了Dockerfile、配置脚本、说明文档等文件,用于构建和运行Ikiwiki Docker容器。 ### 详细知识点 #### Docker容器技术 - Docker基础:Docker是一个开源的应用容器引擎,允许开发者打包他们的应用以及应用的依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)。 - 镜像与容器:在Docker中,镜像(Image)是一个可执行包,包含了运行应用程序所需的所有内容,例如代码、运行时、库、环境变量和配置文件。容器(Container)是从镜像创建的应用运行实例,可以进行启动、停止、删除等操作。每个容器都是相互隔离的,保证应用安全运行。 #### Ikiwiki的配置与部署 - Ikiwiki简介:Ikiwiki是一个用git作为后端的wiki引擎,它允许通过文本文件来编辑网页,支持Markdown、Textile等标记语言,使得内容的编写更加直观和方便。 - 部署要求:部署Ikiwiki通常需要一个web服务器和一些配置来处理HTTP请求。而通过Docker,用户可以快速部署一个预配置好的Ikiwiki环境。 - 配置方式:Docker运行命令中涉及到了多个参数的使用,如`--name`用于给容器命名,`-v`用于指定挂载卷,`-e`用于设置环境变量,`-p`用于端口映射,`-d`用于让容器在后台运行。 #### Docker命令行操作 - docker pull:从Docker Hub或用户指定的仓库拉取指定的镜像。 - docker run:创建一个新的容器并运行一个命令。这里提供了两种运行Ikiwiki的方式,一种是用于生产环境的,与域名绑定并支持SSL;另一种是用于开发或测试环境的,直接在80端口运行。 #### 网络代理和SSL支持 - SSL支持:SSL(Secure Sockets Layer)是一种安全协议,用于保障Web服务器和浏览器之间的通信安全。当容器配置为不支持SSL时,通常意味着不直接处理HTTPS请求。 - Nginx-Proxy:一个Docker镜像,用于运行一个Nginx服务器,充当SSL终止层,将SSL终止在Nginx代理中,然后将非加密的HTTP请求转发到后端的容器。这样可以利用Nginx强大的网络功能来处理HTTPS、HTTP/2等,增强系统的安全性和效率。 ### 总结 在介绍如何部署Ikiwiki wiki引擎到Docker容器的过程中,涉及到了Docker的基本概念、容器的创建和配置、Ikiwiki的运行机制以及Shell命令行的实用操作。文档也提到了在使用不支持SSL的独立容器时,推荐配合Nginx-Proxy来增强安全性和扩展性。这些知识点对于管理和维护Docker容器化的应用具有很高的实用价值。
recommend-type

Unity开发实用指南:快捷键、外部工具与模型创建

### Unity开发实用指南:快捷键、外部工具与模型创建 #### 1. Unity场景导航与键盘快捷键 在使用Unity进行开发时,一个三键鼠标会带来更好的操作体验,虽然Unity也支持单键或双键鼠标,但三键鼠标能让操作更加便捷,在Mac系统上同样适用。 除了使用鼠标进行导航操作外,键盘也能实现一些视图控制功能。当按住鼠标右键时,可以使用键盘上的W、A、S、D键像在第一人称游戏中一样移动视角。在进行其他操作时按住Shift键可以加快移动速度。 而在选择对象后按下F键,场景视图会自动平移和缩放以聚焦该对象。如果在场景导航中迷失方向,可以在层级面板中选择一个对象,将鼠标移到场景视图上(此