P11 (*) Modified run-length encoding.

本文介绍了一种将列表中元素进行编码修改的方法,针对具有重复元素的列表,仅保留重复计数及唯一元素。通过示例展示如何使用Scala实现此功能,包括列表拆分、条件判断及结果映射等关键步骤。
Modify the result of problem  P10  in such a way that if an element has no duplicates it is simply copied into the result list. Only elements with duplicates are transferred as  (N, E)  terms.

Example:

scala> encodeModified(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))
res0: List[Any] = List((4,'a), 'b, (2,'c), (2,'a), 'd, (4,'e))
 
spanList通过递归将列表拆分成多个元素相同的列表,
(takes,lefts)=curList span(_==curList.head)  根据条件将列表分成两部分
 
//11
def encodeModified[A](ls: List[A]) =  {
    def spanList[A](curList:List[A]):List[List[A]]={
      if(curList.isEmpty) List(List())
      else{
        val list=Nil
        val (takes,lefts)=curList span(_==curList.head)
        if(lefts==Nil) List(takes)
        else List(takes):::spanList(lefts)
       }
    }

  spanList(ls).map(e=> if(e.length>1){(e.length,e.head)} else{e.head} )
}

def main(args: Array[String])= {
  println(encodeModified(List(1,1,2,2,3,4,4,5,7)))
}

结果
List((2,1), (2,2), 3, (2,4), 5, 7)
 
参考答案
Starting Redis Server 1:C 09 Jun 2025 12:44:54.319 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 1:C 09 Jun 2025 12:44:54.320 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 1:C 09 Jun 2025 12:44:54.320 * Redis version=8.0.2, bits=64, commit=00000000, modified=1, pid=1, just started 1:C 09 Jun 2025 12:44:54.320 * Configuration loaded 1:M 09 Jun 2025 12:44:54.320 * monotonic clock: POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis Open Source .-`` .-```. ```\/ _.,_ ''-._ 8.0.2 (00000000/1) 64 bit ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 1:M 09 Jun 2025 12:44:54.321 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 1:M 09 Jun 2025 12:44:54.321 * <bf> RedisBloom version 8.0.1 (Git=unknown) 1:M 09 Jun 2025 12:44:54.321 * <bf> Registering configuration options: [ 1:M 09 Jun 2025 12:44:54.321 * <bf> { bf-error-rate : 0.01 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { bf-initial-size : 100 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { bf-expansion-factor : 2 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { cf-bucket-size : 2 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { cf-initial-size : 1024 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { cf-max-iterations : 20 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { cf-expansion-factor : 1 } 1:M 09 Jun 2025 12:44:54.321 * <bf> { cf-max-expansions : 32 } 1:M 09 Jun 2025 12:44:54.321 * <bf> ] 1:M 09 Jun 2025 12:44:54.321 * Module 'bf' loaded from /usr/local/lib/redis/modules//redisbloom.so 1:M 09 Jun 2025 12:44:54.322 * <search> Redis version found by RedisSearch : 8.0.2 - oss 1:M 09 Jun 2025 12:44:54.322 * <search> RediSearch version 8.0.1 (Git=5688fcc) 1:M 09 Jun 2025 12:44:54.322 * <search> Low level api version 1 initialized successfully 1:M 09 Jun 2025 12:44:54.322 * <search> gc: ON, prefix min length: 2, min word length to stem: 4, prefix max expansions: 200, query timeout (ms): 500, timeout policy: return, cursor read size: 1000, cursor max idle (ms): 300000, max doctable size: 1000000, max number of search results: 1000000, 1:M 09 Jun 2025 12:44:54.322 * <search> Initialized thread pools! 1:M 09 Jun 2025 12:44:54.322 * <search> Disabled workers threadpool of size 0 1:M 09 Jun 2025 12:44:54.322 * <search> Subscribe to config changes 1:M 09 Jun 2025 12:44:54.322 * <search> Enabled role change notification 1:M 09 Jun 2025 12:44:54.322 * <search> Cluster configuration: AUTO partitions, type: 0, coordinator timeout: 0ms 1:M 09 Jun 2025 12:44:54.322 * <search> Register write commands 1:M 09 Jun 2025 12:44:54.322 * Module 'search' loaded from /usr/local/lib/redis/modules//redisearch.so 1:M 09 Jun 2025 12:44:54.323 * <timeseries> RedisTimeSeries version 80001, git_sha=577bfa8b5909e7ee572f0b651399be8303dc6641 1:M 09 Jun 2025 12:44:54.323 * <timeseries> Redis version found by RedisTimeSeries : 8.0.2 - oss 1:M 09 Jun 2025 12:44:54.323 * <timeseries> Registering configuration options: [ 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-compaction-policy : } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-num-threads : 3 } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-retention-policy : 0 } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-duplicate-policy : block } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-chunk-size-bytes : 4096 } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-encoding : compressed } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-ignore-max-time-diff: 0 } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> { ts-ignore-max-val-diff : 0.000000 } 1:M 09 Jun 2025 12:44:54.323 * <timeseries> ] 1:M 09 Jun 2025 12:44:54.323 * <timeseries> Detected redis oss 1:M 09 Jun 2025 12:44:54.323 * Module 'timeseries' loaded from /usr/local/lib/redis/modules//redistimeseries.so 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Created new data type 'ReJSON-RL' 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> version: 80001 git sha: unknown branch: unknown 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Exported RedisJSON_V1 API 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Exported RedisJSON_V2 API 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Exported RedisJSON_V3 API 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Exported RedisJSON_V4 API 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Exported RedisJSON_V5 API 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Enabled diskless replication 1:M 09 Jun 2025 12:44:54.323 * <ReJSON> Initialized shared string cache, thread safe: false. 1:M 09 Jun 2025 12:44:54.323 * Module 'ReJSON' loaded from /usr/local/lib/redis/modules//rejson.so 1:M 09 Jun 2025 12:44:54.323 * <search> Acquired RedisJSON_V5 API 1:M 09 Jun 2025 12:44:54.323 * Server initialized 1:M 09 Jun 2025 12:44:54.323 * <search> Loading event starts 1:M 09 Jun 2025 12:44:54.323 * <search> Enabled workers threadpool of size 4 1:M 09 Jun 2025 12:44:54.323 * Loading RDB produced by version 7.4.2 1:M 09 Jun 2025 12:44:54.323 * RDB age 11115 seconds 1:M 09 Jun 2025 12:44:54.323 * RDB memory usage when created 3.81 Mb 1:M 09 Jun 2025 12:44:54.327 # FATAL: Data file was created with a Redis server configured to handle more than 16 databases. Exiting
06-10
PS C:\Users\Administrator\Desktop> # 检查 PowerShell 7 安装路径 PS C:\Users\Administrator\Desktop> $pwshPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" PS C:\Users\Administrator\Desktop> Test-Path $pwshPath False PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 检查版本 PS C:\Users\Administrator\Desktop> & $pwshPath -Command { $PSVersionTable } & : 无法将“C:\Program Files\PowerShell\7\pwsh.exe”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 3 + & $pwshPath -Command { $PSVersionTable } + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program Files\PowerShell\7\pwsh.exe:String) [], CommandNotFoundExcep tion + FullyQualifiedErrorId : CommandNotFoundException 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> if (-not (Test-Path $pwshProfile)) { >> New-Item -Path $pwshProfile -ItemType File -Force >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 添加基础配置 PS C:\Users\Administrator\Desktop> @' >> # 启用现代语法 >> Set-StrictMode -Version 3.0 >> >> # 自定义函数 >> function Invoke-Analyzer { & "E:\DesktopAnalyzer.ps1" } >> function Invoke-Verifier { & "E:\PythonEnvVerifier.ps1" } >> >> 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> # 创建快捷方式 PS C:\Users\Administrator\Desktop> $shortcutPath = "$env:USERPROFILE\Desktop\PowerShell 7.lnk" PS C:\Users\Administrator\Desktop> $WshShell = New-Object -ComObject WScript.Shell PS C:\Users\Administrator\Desktop> $shortcut = $WshShell.CreateShortcut($shortcutPath) PS C:\Users\Administrator\Desktop> $shortcut.TargetPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" PS C:\Users\Administrator\Desktop> $shortcut.Arguments = "-NoExit -Command `". `'$pwshProfile`'`"" PS C:\Users\Administrator\Desktop> $shortcut.IconLocation = "$env:ProgramFiles\PowerShell\7\assets\Powershell_av_colors.ico" PS C:\Users\Administrator\Desktop> $shortcut.Save() PS C:\Users\Administrator\Desktop> # 确保分析脚本存在 PS C:\Users\Administrator\Desktop> if (-not (Test-Path "E:\DesktopAnalyzer.ps1")) { >> @' >> # 桌面分析脚本内容 >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> Write-Host "`n=== 桌面文件分析报告 ===`n" -ForegroundColor Cyan >> >> $items = Get-ChildItem -Path $desktopPath -Force >> if (-not $items) { >> Write-Host "桌面是空的!" -ForegroundColor Green >> exit >> } >> >> # ... 完整脚本内容 ... >> '@ | Set-Content -Path "E:\DesktopAnalyzer.ps1" -Encoding UTF8 >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 确保验证脚本存在 PS C:\Users\Administrator\Desktop> if (-not (Test-Path "E:\PythonEnvVerifier.ps1")) { >> @' >> # 环境验证脚本内容 >> function Verify-Environment { >> # ... 完整脚本内容 ... >> } >> Verify-Environment >> '@ | Set-Content -Path "E:\EnvVerifier.ps1" -Encoding UTF8 >> } PS C:\Users\Administrator\Desktop> # 三元运算符(正确用法) PS C:\Users\Administrator\Desktop> $result = "成功" PS C:\Users\Administrator\Desktop> Write-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' : 'Red') 所在位置 行:1 字符: 63 + ... ite-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' ... + ~ 表达式或语句中包含意外的标记“?”。 所在位置 行:1 字符: 62 + Write-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Gree ... + ~ 表达式中缺少右“)”。 所在位置 行:1 字符: 80 + ... "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' : 'Red') + ~ 表达式或语句中包含意外的标记“)”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken 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 ?? '未设置')" 所在位置 行:1 字符: 35 + Write-Host "PYTHONPATH: $($envVar ?? '未设置')" + ~~ 表达式或语句中包含意外的标记“??”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 管道链运算符 PS C:\Users\Administrator\Desktop> Get-ChildItem *.py | ForEach-Object { "Python文件: $($_.Name)" } Python文件: test_module.py Python文件: verify_path.py PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 简化的错误处理 PS C:\Users\Administrator\Desktop> try { >> Get-Item "C:\不存在路径" -ErrorAction Stop >> } catch { >> Write-Host "错误: $_" -ForegroundColor Red >> } 错误: 找不到路径“C:\不存在路径”,因为该路径不存在。 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 类定义(PowerShell 5+) PS C:\Users\Administrator\Desktop> class FileInfo { >> [string]$Name >> [datetime]$Modified >> [double]$SizeKB >> 所在位置 行:4 字符: 5 + [double]$SizeKB + ~~~~~~~~~~~~~~~ 语句块或类型定义中缺少右“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace PS C:\Users\Administrator\Desktop> FileInfo([System.IO.FileInfo]$file) { >> $this.Name = $file.Name >> $this.Modified = $file.LastWriteTime >> $this.SizeKB = [math]::Round($file.Length / 1KB, 2) >> } FileInfo : 无法将“FileInfo”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 5 + FileInfo([System.IO.FileInfo]$file) { + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (FileInfo:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> } 所在位置 行:1 字符: 1 + } + ~ 表达式或语句中包含意外的标记“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken 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($_) >> } 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound PS C:\Users\Administrator\Desktop> $files | Format-Table Name, Modified, SizeKB PS C:\Users\Administrator\Desktop> # 创建Python虚拟环境 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路径 (clean_env) PS C:\Users\Administrator\Desktop> Write-Host "当前Python: $(which python)" which : 无法将“which”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 25 + Write-Host "当前Python: $(which python)" + ~~~~~ + CategoryInfo : ObjectNotFound: (which:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 当前Python: (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 在虚拟环境中运行脚本 (clean_env) PS C:\Users\Administrator\Desktop> python -c "import sys; print(sys.path)" ['', 'C:\\Users\\Administrator\\Desktop', 'E:\\Python310\\python310.zip', 'E:\\Python310\\DLLs', 'E:\\Python310\\lib', 'E:\\Python310', 'E:\\PythonTools\\clean_env', 'E:\\PythonTools\\clean_env\\lib\\site-packages'] (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 Collecting flask>=2.0.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/f9/7f9263c5695f4bd0023734af91bedb2ff8209e8de6ead162f35d8dc762fd/flask-3.1.2-py3-none-any.whl (103 kB) Collecting python-dotenv Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5f/ed/539768cf28c661b5b068d66d96a2f155c4971a5d55684a514c1a0e0dec2f/python_dotenv-1.1.1-py3-none-any.whl (20 kB) Collecting psutil Using cached https://pypi.tuna.tsinghua.edu.cn/packages/50/1b/6921afe68c74868b4c9fa424dad3be35b095e16687989ebbb50ce4fceb7c/psutil-7.0.0-cp37-abi3-win_amd64.whl (244 kB) Collecting sqlalchemy Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/2d/bfc6b6143adef553a08295490ddc52607ee435b9c751c714620c1b3dd44d/sqlalchemy-2.0.43-cp310-cp310-win_amd64.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 68.2 MB/s eta 0:00:00 Collecting requests Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl (64 kB) Collecting flask-sse Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/83/f9fe86f554a153fdd300fb8027121d508a2177605bd158d967ddd7325948/Flask_SSE-1.0.0-py2.py3-none-any.whl (5.0 kB) Collecting itsdangerous>=2.2.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl (16 kB) Collecting blinker>=1.9.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl (8.5 kB) Collecting markupsafe>=2.1.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/44/06/e7175d06dd6e9172d4a69a72592cb3f7a996a9c396eee29082826449bbc3/MarkupSafe-3.0.2-cp310-cp310-win_amd64.whl (15 kB) Collecting werkzeug>=3.1.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl (224 kB) Collecting jinja2>=3.1.2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl (134 kB) Collecting click>=8.1.3 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl (102 kB) Collecting typing-extensions>=4.6.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b5/00/d631e67a838026495268c2f6884f3711a15a9a2a96cd244fdaea53b823fb/typing_extensions-4.14.1-py3-none-any.whl (43 kB) Collecting greenlet>=1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/6f/b60b0291d9623c496638c582297ead61f43c4b72eef5e9c926ef4565ec13/greenlet-3.2.4-cp310-cp310-win_amd64.whl (298 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 298.7/298.7 kB ? eta 0:00:00 Collecting certifi>=2017.4.17 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl (161 kB) Collecting charset_normalizer<4,>=2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e2/c6/f05db471f81af1fa01839d44ae2a8bfeec8d2a8b4590f16c4e7393afd323/charset_normalizer-3.4.3-cp310-cp310-win_amd64.whl (107 kB) Collecting urllib3<3,>=1.21.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl (129 kB) Collecting idna<4,>=2.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB) Collecting six Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Collecting redis Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e8/02/89e2ed7e85db6c93dfa9e8f691c5087df4e3551ab39081a4d7c6d1f90e05/redis-6.4.0-py3-none-any.whl (279 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 279.8/279.8 kB ? eta 0:00:00 Collecting colorama Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB) Collecting async-timeout>=4.0.3 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fe/ba/e2081de779ca30d473f21f5b30e0e737c438205440784c7dfc81efc2b029/async_timeout-5.0.1-py3-none-any.whl (6.2 kB) Installing collected packages: urllib3, typing-extensions, six, python-dotenv, psutil, markupsafe, itsdangerous, idna, greenlet, colorama, charset_normalizer, certifi, blinker, async-timeout, werkzeug, sqlalchemy, requests, redis, jinja2, click, flask, flask-sse Successfully installed async-timeout-5.0.1 blinker-1.9.0 certifi-2025.8.3 charset_normalizer-3.4.3 click-8.2.1 colorama-0.4.6 flask-3.1.2 flask-sse-1.0.0 greenlet-3.2.4 idna-3.10 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.2 psutil-7.0.0 python-dotenv-1.1.1 redis-6.4.0 requests-2.32.5 six-1.17.0 sqlalchemy-2.0.43 typing-extensions-4.14.1 urllib3-2.5.0 werkzeug-3.1.3 [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> # 运行Python脚本 (clean_env) PS C:\Users\Administrator\Desktop> python "E:\verify_path.py" E:\Python310\python.exe: can't open file 'E:\\verify_path.py': [Errno 2] No such file or directory (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" >> >> Invoke-WebRequest -Uri $url -OutFile $output >> Start-Process msiexec.exe -ArgumentList "/i `"$output`" /qn" -Wait >> Remove-Item $output -Force >> } 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 >> >> # 创建脚本文件 >> # ... >> >> # 创建快捷方式 >> # ... >> >> 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> # .\Setup-PowerShell7.ps1 -Install -Configure PS C:\Users\Administrator\Desktop> .\Setup-PowerShell7.ps1 -Install -Configure .\Setup-PowerShell7.ps1 : 无法将“.\Setup-PowerShell7.ps1”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + .\Setup-PowerShell7.ps1 -Install -Configure + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (.\Setup-PowerShell7.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> da # 运行桌面分析 da : 无法将“da”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + da # 运行桌面分析 + ~~ + CategoryInfo : ObjectNotFound: (da:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> ve # 运行环境验证 ve : 无法将“ve”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + ve # 运行环境验证 + ~~ + CategoryInfo : ObjectNotFound: (ve:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> clean # 清理桌面 clean : 无法将“clean”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + clean # 清理桌面 + ~~~~~ + CategoryInfo : ObjectNotFound: (clean:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> # 创建并激活环境 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 Collecting pandas Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/df/5ab92fcd76455a632b3db34a746e1074d432c0cdbbd28d7cd1daba46a75d/pandas-2.3.2-cp310-cp310-win_amd64.whl (11.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 81.8 MB/s eta 0:00:00 Collecting numpy>=1.22.4 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dd/4b822569d6b96c39d1215dbae0582fd99954dcbcf0c1a13c61783feaca3f/numpy-2.2.6-cp310-cp310-win_amd64.whl (12.9 MB) Collecting pytz>=2020.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/81/c4/34e93fe5f5429d7570ec1fa436f1986fb1f00c3e0f43a589fe2bbcd22c3f/pytz-2025.2-py2.py3-none-any.whl (509 kB) Collecting tzdata>=2022.7 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl (347 kB) Collecting python-dateutil>=2.8.2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB) Collecting six>=1.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Installing collected packages: pytz, tzdata, six, numpy, python-dateutil, pandas Successfully installed numpy-2.2.6 pandas-2.3.2 python-dateutil-2.9.0.post0 pytz-2025.2 six-1.17.0 tzdata-2025.2 [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 myscript.py E:\Python310\python.exe: can't open file 'C:\\Users\\Administrator\\Desktop\\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> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser PS C:\Users\Administrator\Desktop> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser PS C:\Users\Administrator\Desktop> $scriptPath = Join-Path $PSScriptRoot "myscript.ps1" Join-Path : 无法将参数绑定到参数“Path”,因为该参数为空字符串。 所在位置 行:1 字符: 25 + $scriptPath = Join-Path $PSScriptRoot "myscript.ps1" + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Join-Path],ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Join PathCommand PS C:\Users\Administrator\Desktop>
最新发布
08-24
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>
08-24
WebSocket错误: Handshake status 200 OK -+-+- {'date': 'Mon, 30 Jun 2025 08:02:54 GMT', 'content-type': 'text/html', 'content-length': '567', 'connection': 'keep-alive', 'last-modified': 'Thu, 22 May 2025 06:37:06 GMT', 'vary': 'Accept-Encoding', 'etag': '"682ec612-237"', 'cache-control': 'no-cache', 'accept-ranges': 'bytes', 'x-frame-options': 'sameorigin', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval'; worker-src * blob:", 'access-control-allow-origin': '*'} -+-+- b'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon"><script defer="defer" src="/base/static/js/runtime~main.557ce0b5.js"></script><script defer="defer" src="/base/static/js/tools-3b28af8c.557ce0b5.js"></script><script defer="defer" src="/base/static/js/tools-cdd60c62.557ce0b5.js"></script><script defer="defer" src="/base/static/js/main.557ce0b5.js"></script></head><body><div id="base-root"></div><script src="/base/base-framework/config.js"></script></body></html>' 2025-06-30 16:02:53,963 - websocket - ERROR - Handshake status 200 OK -+-+- {'date': 'Mon, 30 Jun 2025 08:02:54 GMT', 'content-type': 'text/html', 'content-length': '567', 'connection': 'keep-alive', 'last-modified': 'Thu, 22 May 2025 06:37:06 GMT', 'vary': 'Accept-Encoding', 'etag': '"682ec612-237"', 'cache-control': 'no-cache', 'accept-ranges': 'bytes', 'x-frame-options': 'sameorigin', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval'; worker-src * blob:", 'access-control-allow-origin': '*'} -+-+- b'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon"><script defer="defer" src="/base/static/js/runtime~main.557ce0b5.js"></script><script defer="defer" src="/base/static/js/tools-3b28af8c.557ce0b5.js"></script><script defer="defer" src="/base/static/js/tools-cdd60c62.557ce0b5.js"></script><script defer="defer" src="/base/static/js/main.557ce0b5.js"></script></head><body><div id="base-root"></div><script src="/base/base-framework/config.js"></script></body></html>' - goodbye 报错
07-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值