Command Search 1.0.0.

C语言文件搜索与系统路径
程序说明:

Command Search 1.0.0.使用参数中文版

 写这个程序真累啊,一边玩一边写,几天时间就这样过去了。写到现在终于写完了,腰酸背痛,腿....嘿~0~,
 首先想说的是很感谢犬犬对我写程序时所遇到的困难,给予的指点,攻破了程序最关键的技术问题,再次感谢!

 程序使用很简单,但对和我一样E文不好的朋友,第一次使用可能有点麻烦,这里把参数使用的中英文写了下来,由于本人英语水平连小学生都不如(郁闷啊....),故不得不借助"金山快译2005"逐字逐句进行翻译,当中可能有很多不正确的病语,可能闹出不少笑话,懂E文的老鸟们可得多多见谅了,别嘲笑小弟哈~如果愿意帮忙的话,请论坛或MSN中联系我,帮助我改正病语^_^!
     
 命令行下输入cs help就可以得到如下E文帮助,(/**/内为中文解释):
Search the system document- hidden document, the procedure can change the document time to belong to sex
/*搜索系统文件---隐藏的文件,程序能改变文件时间属性*/

CS [drive:][path][filename] [r+]

Specifies CS, directory, and/or files to list or Change
/*叙述 CS ,目录及[或] 文件列出或改变*/
CS [drive:][path]       System、 Conceal files to list
                             /* 列出系统及隐藏文件*/

CS [drive:][path] +r    Own modification of procedure
                           /*拥有程序的修正,既缺省的修改*/

CS [drive:][path] +r +r I to make decision
                         /*我作出决定,既自定义修改参数*/

这里详细讲解下程序的具体使用方法:

比如我要列出c:/根目录所有文件,包括系统及隐藏文件,输入命令:
cs c:/
$ The document of the catalogue c:/

c:/*.*
1.COM      /32/      |4095|
3.TXT      /32/      |50|
ARCLDR.EXE      /39/      |19456|
ARCSETUP.EXE      /39/      |-32768|
AUTOEXEC.BAT      /35/      |49|
BMP.TXT      /32/      |7635|
BOOT.INI      /39/      |194|
BOOTFONT.BIN      /39/      |-23056|
CCC.TXT      /32/      |0|
CMD.TXT      /32/      |0|
CONFIG.SYS      /2/      |0|
CONFLG.SYS      /3/      |1238|
CS.EXE      /32/      |17352|
EDUO.RAR      /32/      |-30102|
FANGJIAN.TXT      /32/      |763|
GG.TXT      /32/      |0|
IO.SYS      /39/      |0|
IPC$.C      /32/      |508|
MSDOS.SYS      /39/      |0|
NTDETECT.COM      /39/      |-30812|
NTLDR      /39/      |24480|
PERL.TXT      /32/      |1117|
REGEDI~1.TXT      /32/      |1090|
SNMPUTIL.EXE      /32/      |8464|

既可得到如下信息:
列出的文件后面的符号说明下:
其中"//"内的数字代表文件属性,大多是系统文件和隐藏文件,"||"内的数字代表文件的字节大小.

  如果要得到子目录的文件列表,必须要在路径名后加/,否则程序会找不到路径而出错.如:

cs C:/Inetpub/wwwroot/

#############################################################

接下来讲如何修改文件的时间了....

输入命令 cs C:/Inetpub/wwwroot/404.htm r+  如下:

C:/>cs C:/Inetpub/wwwroot/404.htm r+
C:/Inetpub/wwwroot/404.htm

 Volume in drive C has no label
 Volume Serial Number is 18D5-58CE
 Directory of C:/INETPUB/WWWROOT

404      HTM        22 99-01-16    2:01
        1 file(s)         22 bytes
                  1023932928 bytes free

 Volume in drive C has no label
 Volume Serial Number is 18D5-58CE
 Directory of C:/INETPUB/WWWROOT

404      HTM        22 04-12-18    3:03
        1 file(s)         22 bytes
                  1023932928 bytes free

这里把C:/Inetpub/wwwroot/404.htm的时间从99-01-16    2:01修改到了04-12-18    3:03
这是程序默认的修改文件的时间,如果要自己定义修改文件的时间,就要再在后面加参数 r+ 如:

C:/>cs C:/Inetpub/wwwroot/404.htm r+ r+

Year:1-Month:17-Day:26-Hour:8-5Minute-Second:9C:/Inetpub/wwwroot/404.htm

 Volume in drive C has no label
 Volume Serial Number is 18D5-58CE
 Directory of C:/INETPUB/WWWROOT

404      HTM        22 04-12-18    3:03
        1 file(s)         22 bytes
                  1023932928 bytes free

 Volume in drive C has no label
 Volume Serial Number is 18D5-58CE
 Directory of C:/INETPUB/WWWROOT

404      HTM        22 81-01-26    8:05
        1 file(s)         22 bytes
                  1023932928 bytes free

当键入这个参数后,程序会提示用户依次输入年-月-日-时-分-秒 六个参数,参数我使用的是16进制 ,如:0x0,就是1980年(程序所能接受最早时间是1980年,这是C语言函数的限制),或直接输入0,也是同样的效果。1就是1981年,2就是1982年,依次类推,当然,你也可以用八进制输入,比如000就是80年,001就是81年...007就是87年,010就是88年,类推...你也可以使用你熟悉的进制,比如10进制什么的:).反正随自己的爱好啦。其它的月-日-时-分-秒可以按随便输入,但是要合理的,例如,月份最多就是31号,两位数字,你总不能输入310或更多的数字吧?如果这样输入了,那么恭喜你,程序未对输入的正确性做检查,到底程序会把文件修改成什么月份我也不知道。所以在输入的时候请仔细检查输入的参数。注:修改文件时间不支持统配符号 !

这里要谈到程序的一点bug,如果在输入帮助时,输入的不是help或输入少了或输入多了,均会造成程序错误,例如:

C:/>cs helpo
$ The document of the catalogue helpo

helpo*.*

这里参数多输入了一个O,程序返回的结果是错误的,因为命令行的第一参数也是列目录的函数需要调用的,也就是在第一个参数不等于help时列目录的函数会调用第一个参数来运行,结果造成如此错误。呵呵~在编写程序时,我是假设用户输入help是正确、成功的,没有做过多检查,也相信使用者不会犯如此低级的错误吧?^_^

此程序有一定的欺诈性质,请不要用来做坏事!如果在使用中遇到什么问题或有什么好的建议,请访问我们的论坛
http://www.52chb.com/bbs/
http://bbs.52chb.com或直接联系我,我的MsN是:Net2K_@MsN.CoM

程序下载:
http://www.52chb.com/bbs/Announce/Announce.asp?BoardID=11&ID=737

运行环境:9x/NT/2K/XP/2003


','''╭⌒╮⌒╮.',''',,',.'',,','',.
 ╱◥██◣''o┈网事本如风┄o.'',,',.  
︱田︱田田| '',,',.o┈恍如煙雨中┄
╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
做个弹弓,打小日本家玻璃
抗日--要从娃娃抓起







PS C:\Users\Administrator\Desktop> # ===== 修复插件逻辑 ===== PS C:\Users\Administrator\Desktop> function Install-PthFixPlugin { >> param( >> [string]$PythonPath = "E:\Python310" >> ) >> >> $sitePackages = "$PythonPath\Lib\site-packages" >> $pluginRoot = "$sitePackages\pth_fix_plugin" >> >> # 创建插件目录结构 >> $packageDir = "$pluginRoot\pth_fix_plugin" >> New-Item -ItemType Directory -Path $packageDir -Force | Out-Null >> >> # 创建插件内容(增强删除逻辑) >> $pluginFile = "$packageDir\__init__.py" >> @' >> # pth_fix_plugin/__init__.py >> import os >> import sys >> import sysconfig >> import traceback >> import shutil >> import atexit >> from setuptools.command.install import install >> >> class CustomInstallCommand(install): >> """Custom install command to prevent .pth file generation""" >> >> def run(self): >> # 调用原始安装方法 >> install.run(self) >> >> # 修复.pth文件 >> self.fix_pth_file() >> >> def fix_pth_file(self): >> """Fix the .pth file issue with enhanced logic""" >> try: >> # 获取所有可能的site-packages路径 >> possible_paths = [ >> sysconfig.get_paths()["purelib"], >> sysconfig.get_paths()["platlib"], >> os.path.join(sys.prefix, "Lib", "site-packages"), >> os.path.join(sys.exec_prefix, "Lib", "site-packages") >> ] >> >> # 去重并添加可能的子目录 >> search_paths = set() >> for path in possible_paths: >> if os.path.exists(path): >> search_paths.add(path) >> # 添加所有子目录 >> search_paths.update( >> os.path.join(path, d) for d in os.listdir(path) >> if os.path.isdir(os.path.join(path, d)) >> ) >> >> # 在所有可能路径中搜索并删除.pth文件 >> removed = False >> for path in search_paths: >> pth_path = os.path.join(path, 'distutils-precedence.pth') >> if os.path.exists(pth_path): >> try: >> # 尝试删除文件 >> os.remove(pth_path) >> print(f"[SUCCESS] Removed .pth file: {pth_path}") >> removed = True >> except Exception as e: >> # 如果删除失败,尝试移动文件 >> try: >> backup_path = pth_path + ".bak" >> shutil.move(pth_path, backup_path) >> print(f"[SUCCESS] Moved .pth file to backup: {backup_path}") >> removed = True >> except Exception as e2: >> print(f"[ERROR] Failed to handle .pth file: {str(e2)}") >> traceback.print_exc() >> >> if not removed: >> print("[INFO] No .pth file found in any location") >> >> except Exception as e: >> print(f"[CRITICAL] Error: {str(e)}") >> traceback.print_exc() >> >> # 注册退出时检查 >> atexit.register(self.verify_clean_environment) >> >> def verify_clean_environment(self): >> """Verify no .pth file exists after installation""" >> for path in [ >> sysconfig.get_paths()["purelib"], >> os.path.join(sys.prefix, "Lib", "site-packages") >> ]: >> pth_path = os.path.join(path, 'distutils-precedence.pth') >> if os.path.exists(pth_path): >> print(f"[WARNING] .pth file still present: {pth_path}") >> '@ | Set-Content -Path $pluginFile -Encoding ASCII -Force >> >> # 创建入口点配置 >> $setupFile = "$pluginRoot\setup.py" >> @' >> from setuptools import setup >> >> setup( >> name='pth_fix_plugin', >> version='1.0.0', >> packages=['pth_fix_plugin'], >> entry_points={ >> 'distutils.commands': [ >> 'install = pth_fix_plugin:CustomInstallCommand', >> ], >> }, >> ) >> '@ | Set-Content -Path $setupFile -Encoding ASCII -Force >> >> # 创建pyproject.toml文件 >> $pyprojectFile = "$pluginRoot\pyproject.toml" >> @' >> [build-system] >> requires = ["setuptools>=40.8.0", "wheel"] >> build-backend = "setuptools.build_meta" >> '@ | Set-Content -Path $pyprojectFile -Encoding ASCII -Force >> >> # 安装插件(使用常规安装模式) >> Push-Location -Path $pluginRoot >> try { >> # 使用常规模式安装(非可编辑模式) >> python -m pip install . --no-deps --force-reinstall --no-warn-script-location >> } catch { >> Write-Host "❌ Failed to install plugin: $_" -ForegroundColor Red >> } >> Pop-Location >> >> Write-Host "✅ pth_fix plugin installed successfully" -ForegroundColor Green >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 增强的验证函数 ===== PS C:\Users\Administrator\Desktop> function Test-FullEnvironment { >> param( >> [string]$PythonPath = "E:\Python310" >> ) >> >> # 验证核心组件 >> $coreComponents = python -c "import torch, torchvision, torchaudio, numpy as np, modelscope; print(f'PyTorch: {torch.__version__}\nTorchVision: {torchvision.__version__}\nTorchAudio: {torchaudio.__version__}\nNumPy: {np.__version__}\nAudio Backend: {torchaudio.get_audio_backend()}\nModelScope: {modelscope.__version__}')" >> Write-Host $coreComponents >> >> # 验证警告 >> $warnings = python -c "import warnings; warnings.filterwarnings('error'); import modelscope" 2>&1 >> if ($LASTEXITCODE -eq 0) { >> Write-Host "✅ Environment has no warnings" -ForegroundColor Green >> } else { >> Write-Host "❌ Environment has warnings: $warnings" -ForegroundColor Red >> } >> >> # 验证.pth文件 >> $sitePackages = "$PythonPath\Lib\site-packages" >> if (Test-Path $sitePackages) { >> $pthFiles = Get-ChildItem $sitePackages -Recurse -Filter "distutils-precedence.pth" -ErrorAction SilentlyContinue >> >> if ($pthFiles) { >> Write-Host "⚠️ Found .pth file: $($pthFiles.FullName)" -ForegroundColor Yellow >> } else { >> Write-Host "✅ No distutils-precedence.pth file found" -ForegroundColor Green >> } >> >> # 增强的入口点验证 >> $pluginStatus = python -c @" >> import sys >> import os >> import traceback >> from importlib.metadata import entry_points, distribution >> >> try: >> # 检查插件是否已安装 >> dist = distribution('pth_fix_plugin') >> print(f"Plugin installed: {dist.metadata['Name']} v{dist.metadata['Version']}") >> >> # 检查入口点是否注册 >> install_eps = entry_points(group='distutils.commands', name='install') >> >> if not install_eps: >> print('ERROR: No install command entry points found') >> sys.exit(1) >> >> pth_fix_found = any('pth_fix_plugin' in ep.value for ep in install_eps) >> >> if pth_fix_found: >> print('SUCCESS: Install command hook active') >> else: >> print('ERROR: Install command not hooked') >> sys.exit(1) >> >> except Exception as e: >> print(f'ERROR: {str(e)}') >> traceback.print_exc() >> sys.exit(1) >> "@ >> >> # 解析插件状态输出 >> if ($pluginStatus -match "ERROR:") { >> Write-Host "❌ Plugin status check failed: $pluginStatus" -ForegroundColor Red >> } elseif ($pluginStatus -match "SUCCESS:") { >> Write-Host "✅ $($pluginStatus | Select-String 'SUCCESS:.*')" -ForegroundColor Green >> } else { >> Write-Host $pluginStatus >> } >> } else { >> Write-Host "❌ Path does not exist: $sitePackages" -ForegroundColor Red >> } >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 执行最终修复 ===== PS C:\Users\Administrator\Desktop> # 1. 卸载现有插件 PS C:\Users\Administrator\Desktop> python -m pip uninstall -y pth_fix_plugin Found existing installation: pth_fix_plugin 1.0.0 Uninstalling pth_fix_plugin-1.0.0: Successfully uninstalled pth_fix_plugin-1.0.0 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 2. 确保插件目录完全删除 PS C:\Users\Administrator\Desktop> $pluginPath = "E:\Python310\Lib\site-packages\pth_fix_plugin" PS C:\Users\Administrator\Desktop> if (Test-Path $pluginPath) { >> Remove-Item -Path $pluginPath -Recurse -Force >> Write-Host "Removed old plugin directory: $pluginPath" -ForegroundColor Cyan >> } Removed old plugin directory: E:\Python310\Lib\site-packages\pth_fix_plugin PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 3. 手动删除所有可能的.pth文件 PS C:\Users\Administrator\Desktop> $searchPaths = @( >> "E:\Python310\Lib\site-packages", >> "E:\Python310\Lib\site-packages\distutils-precedence.pth", >> "E:\Python310\Lib\site-packages\*.dist-info", >> "E:\Python310\Lib\site-packages\*.egg-info" >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> foreach ($path in $searchPaths) { >> if (Test-Path $path) { >> Get-ChildItem $path -Recurse -Filter "distutils-precedence.pth" | ForEach-Object { >> Remove-Item $_.FullName -Force >> Write-Host "Removed .pth file: $($_.FullName)" -ForegroundColor Yellow >> } >> >> # 删除备份文件 >> Get-ChildItem $path -Recurse -Filter "distutils-precedence.pth.bak" | ForEach-Object { >> Remove-Item $_.FullName -Force >> Write-Host "Removed backup file: $($_.FullName)" -ForegroundColor DarkYellow >> } >> } >> } Removed .pth file: E:\Python310\Lib\site-packages\distutils-precedence.pth PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 4. 重新安装插件 PS C:\Users\Administrator\Desktop> Install-PthFixPlugin -PythonPath "E:\Python310" Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Processing e:\python310\lib\site-packages\pth_fix_plugin Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: pth_fix_plugin Building wheel for pth_fix_plugin (pyproject.toml) ... done Created wheel for pth_fix_plugin: filename=pth_fix_plugin-1.0.0-py3-none-any.whl size=2315 sha256=bade234c98098fab9610d063b1b29131a85033c07271f7a0c36a375345545518 Stored in directory: C:\Users\Administrator\AppData\Local\Temp\pip-ephem-wheel-cache-2j8ktxyt\wheels\c7\cc\8f\a13f1f3c2e3c649409279b7caed95e5210d22da47147eaf764 Successfully built pth_fix_plugin Installing collected packages: pth_fix_plugin Successfully installed pth_fix_plugin-1.0.0 ✅ pth_fix plugin installed successfully PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 5. 验证环境 PS C:\Users\Administrator\Desktop> Test-FullEnvironment -PythonPath "E:\Python310" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile ModelScope: 1.29.0 ✅ Environment has no warnings ✅ No distutils-precedence.pth file found File "<string>", line 9 print(fPlugin ^ SyntaxError: '(' was never closed PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 6. 测试修复持久性 PS C:\Users\Administrator\Desktop> python -m pip install --upgrade setuptools --force-reinstall Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting setuptools Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl (1.2 MB) Installing collected packages: setuptools Attempting uninstall: setuptools Found existing installation: setuptools 80.9.0 Uninstalling setuptools-80.9.0: Successfully uninstalled setuptools-80.9.0 Successfully installed setuptools-80.9.0 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 7. 重新验证环境(确保插件在升级后仍有效) PS C:\Users\Administrator\Desktop> Test-FullEnvironment -PythonPath "E:\Python310" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile ModelScope: 1.29.0 ✅ Environment has no warnings ⚠️ Found .pth file: E:\Python310\Lib\site-packages\distutils-precedence.pth File "<string>", line 9 print(fPlugin ^ SyntaxError: '(' was never closed PS C:\Users\Administrator\Desktop> # ===== 修复插件逻辑 ===== PS C:\Users\Administrator\Desktop> function Install-PthFixPlugin { >> param( >> [string]$PythonPath = "E:\Python310" >> ) >> >> $sitePackages = "$PythonPath\Lib\site-packages" >> $pluginRoot = "$sitePackages\pth_fix_plugin" >> >> # 创建插件目录结构 >> $packageDir = "$pluginRoot\pth_fix_plugin" >> New-Item -ItemType Directory -Path $packageDir -Force | Out-Null >> >> # 创建插件内容(增强删除逻辑) >> $pluginFile = "$packageDir\__init__.py" >> @' >> # pth_fix_plugin/__init__.py >> import os >> import sys >> import sysconfig >> import traceback >> import shutil >> import atexit >> from setuptools.command.install import install >> >> class CustomInstallCommand(install): >> """Custom install command to prevent .pth file generation""" >> >> def run(self): >> # 调用原始安装方法 >> install.run(self) >> >> # 修复.pth文件 >> self.fix_pth_file() >> >> def fix_pth_file(self): >> """Fix the .pth file issue with enhanced logic""" >> try: >> # 获取所有可能的site-packages路径 >> possible_paths = [ >> sysconfig.get_paths()["purelib"], >> sysconfig.get_paths()["platlib"], >> os.path.join(sys.prefix, "Lib", "site-packages"), >> os.path.join(sys.exec_prefix, "Lib", "site-packages") >> ] >> >> # 去重并添加可能的子目录 >> search_paths = set() >> for path in possible_paths: >> if os.path.exists(path): >> search_paths.add(path) >> # 添加所有子目录 >> search_paths.update( >> os.path.join(path, d) for d in os.listdir(path) >> if os.path.isdir(os.path.join(path, d)) >> ) >> >> # 在所有可能路径中搜索并删除.pth文件 >> removed = False >> for path in search_paths: >> pth_path = os.path.join(path, 'distutils-precedence.pth') >> if os.path.exists(pth_path): >> try: >> # 尝试删除文件 >> os.remove(pth_path) >> print(f"[SUCCESS] Removed .pth file: {pth_path}") >> removed = True >> except Exception as e: >> # 如果删除失败,尝试移动文件 >> try: >> backup_path = pth_path + ".bak" >> shutil.move(pth_path, backup_path) >> print(f"[SUCCESS] Moved .pth file to backup: {backup_path}") >> removed = True >> except Exception as e2: >> print(f"[ERROR] Failed to handle .pth file: {str(e2)}") >> traceback.print_exc() >> >> if not removed: >> print("[INFO] No .pth file found in any location") >> >> except Exception as e: >> print(f"[CRITICAL] Error: {str(e)}") >> traceback.print_exc() >> >> # 注册退出时检查 >> atexit.register(self.verify_clean_environment) >> >> def verify_clean_environment(self): >> """Verify no .pth file exists after installation""" >> for path in [ >> sysconfig.get_paths()["purelib"], >> os.path.join(sys.prefix, "Lib", "site-packages") >> ]: >> pth_path = os.path.join(path, 'distutils-precedence.pth') >> if os.path.exists(pth_path): >> print(f"[WARNING] .pth file still present: {pth_path}") >> '@ | Set-Content -Path $pluginFile -Encoding ASCII -Force >> >> # 创建入口点配置 >> $setupFile = "$pluginRoot\setup.py" >> @' >> from setuptools import setup >> >> setup( >> name='pth_fix_plugin', >> version='1.0.0', >> packages=['pth_fix_plugin'], >> entry_points={ >> 'distutils.commands': [ >> 'install = pth_fix_plugin:CustomInstallCommand', >> ], >> }, >> ) >> '@ | Set-Content -Path $setupFile -Encoding ASCII -Force >> >> # 创建pyproject.toml文件 >> $pyprojectFile = "$pluginRoot\pyproject.toml" >> @' >> [build-system] >> requires = ["setuptools>=40.8.0", "wheel"] >> build-backend = "setuptools.build_meta" >> '@ | Set-Content -Path $pyprojectFile -Encoding ASCII -Force >> >> # 安装插件(使用常规安装模式) >> Push-Location -Path $pluginRoot >> try { >> # 使用常规模式安装(非可编辑模式) >> python -m pip install . --no-deps --force-reinstall --no-warn-script-location >> } catch { >> Write-Host "❌ Failed to install plugin: $_" -ForegroundColor Red >> } >> Pop-Location >> >> Write-Host "✅ pth_fix plugin installed successfully" -ForegroundColor Green >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 增强的验证函数 ===== PS C:\Users\Administrator\Desktop> function Test-FullEnvironment { >> param( >> [string]$PythonPath = "E:\Python310" >> ) >> >> # 验证核心组件 >> $coreComponents = python -c "import torch, torchvision, torchaudio, numpy as np, modelscope; print(f'PyTorch: {torch.__version__}\nTorchVision: {torchvision.__version__}\nTorchAudio: {torchaudio.__version__}\nNumPy: {np.__version__}\nAudio Backend: {torchaudio.get_audio_backend()}\nModelScope: {modelscope.__version__}')" >> Write-Host $coreComponents >> >> # 验证警告 >> $warnings = python -c "import warnings; warnings.filterwarnings('error'); import modelscope" 2>&1 >> if ($LASTEXITCODE -eq 0) { >> Write-Host "✅ Environment has no warnings" -ForegroundColor Green >> } else { >> Write-Host "❌ Environment has warnings: $warnings" -ForegroundColor Red >> } >> >> # 验证.pth文件 >> $sitePackages = "$PythonPath\Lib\site-packages" >> if (Test-Path $sitePackages) { >> $pthFiles = Get-ChildItem $sitePackages -Recurse -Filter "distutils-precedence.pth" -ErrorAction SilentlyContinue >> >> if ($pthFiles) { >> Write-Host "⚠️ Found .pth file: $($pthFiles.FullName)" -ForegroundColor Yellow >> } else { >> Write-Host "✅ No distutils-precedence.pth file found" -ForegroundColor Green >> } >> >> # 增强的入口点验证 >> $pluginStatus = python -c @" >> import sys >> import os >> import traceback >> from importlib.metadata import entry_points, distribution >> >> try: >> # 检查插件是否已安装 >> dist = distribution('pth_fix_plugin') >> print(f"Plugin installed: {dist.metadata['Name']} v{dist.metadata['Version']}") >> >> # 检查入口点是否注册 >> install_eps = entry_points(group='distutils.commands', name='install') >> >> if not install_eps: >> print('ERROR: No install command entry points found') >> sys.exit(1) >> >> pth_fix_found = any('pth_fix_plugin' in ep.value for ep in install_eps) >> >> if pth_fix_found: >> print('SUCCESS: Install command hook active') >> else: >> print('ERROR: Install command not hooked') >> sys.exit(1) >> >> except Exception as e: >> print(f'ERROR: {str(e)}') >> traceback.print_exc() >> sys.exit(1) >> "@ >> >> # 解析插件状态输出 >> if ($pluginStatus -match "ERROR:") { >> Write-Host "❌ Plugin status check failed: $pluginStatus" -ForegroundColor Red >> } elseif ($pluginStatus -match "SUCCESS:") { >> Write-Host "✅ $($pluginStatus | Select-String 'SUCCESS:.*')" -ForegroundColor Green >> } else { >> Write-Host $pluginStatus >> } >> } else { >> Write-Host "❌ Path does not exist: $sitePackages" -ForegroundColor Red >> } >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 执行最终修复 ===== PS C:\Users\Administrator\Desktop> # 1. 卸载现有插件 PS C:\Users\Administrator\Desktop> python -m pip uninstall -y pth_fix_plugin Found existing installation: pth_fix_plugin 1.0.0 Uninstalling pth_fix_plugin-1.0.0: Successfully uninstalled pth_fix_plugin-1.0.0 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 2. 确保插件目录完全删除 PS C:\Users\Administrator\Desktop> $pluginPath = "E:\Python310\Lib\site-packages\pth_fix_plugin" PS C:\Users\Administrator\Desktop> if (Test-Path $pluginPath) { >> Remove-Item -Path $pluginPath -Recurse -Force >> Write-Host "Removed old plugin directory: $pluginPath" -ForegroundColor Cyan >> } Removed old plugin directory: E:\Python310\Lib\site-packages\pth_fix_plugin PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 3. 手动删除所有可能的.pth文件 PS C:\Users\Administrator\Desktop> $searchPaths = @( >> "E:\Python310\Lib\site-packages", >> "E:\Python310\Lib\site-packages\distutils-precedence.pth", >> "E:\Python310\Lib\site-packages\*.dist-info", >> "E:\Python310\Lib\site-packages\*.egg-info" >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> foreach ($path in $searchPaths) { >> if (Test-Path $path) { >> Get-ChildItem $path -Recurse -Filter "distutils-precedence.pth" | ForEach-Object { >> Remove-Item $_.FullName -Force >> Write-Host "Removed .pth file: $($_.FullName)" -ForegroundColor Yellow >> } >> >> # 删除备份文件 >> Get-ChildItem $path -Recurse -Filter "distutils-precedence.pth.bak" | ForEach-Object { >> Remove-Item $_.FullName -Force >> Write-Host "Removed backup file: $($_.FullName)" -ForegroundColor DarkYellow >> } >> } >> } Removed .pth file: E:\Python310\Lib\site-packages\distutils-precedence.pth PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 4. 重新安装插件 PS C:\Users\Administrator\Desktop> Install-PthFixPlugin -PythonPath "E:\Python310" Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Processing e:\python310\lib\site-packages\pth_fix_plugin Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: pth_fix_plugin Building wheel for pth_fix_plugin (pyproject.toml) ... done Created wheel for pth_fix_plugin: filename=pth_fix_plugin-1.0.0-py3-none-any.whl size=2315 sha256=b847a78506e0fe8125855f49f56387d6086160392cd987a3f7d123c826ffca43 Stored in directory: C:\Users\Administrator\AppData\Local\Temp\pip-ephem-wheel-cache-j61dy6q6\wheels\c7\cc\8f\a13f1f3c2e3c649409279b7caed95e5210d22da47147eaf764 Successfully built pth_fix_plugin Installing collected packages: pth_fix_plugin Successfully installed pth_fix_plugin-1.0.0 ✅ pth_fix plugin installed successfully PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 5. 验证环境 PS C:\Users\Administrator\Desktop> Test-FullEnvironment -PythonPath "E:\Python310" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile ModelScope: 1.29.0 ✅ Environment has no warnings ✅ No distutils-precedence.pth file found File "<string>", line 9 print(fPlugin ^ SyntaxError: '(' was never closed PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 6. 测试修复持久性 PS C:\Users\Administrator\Desktop> python -m pip install --upgrade setuptools --force-reinstall Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting setuptools Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl (1.2 MB) Installing collected packages: setuptools Attempting uninstall: setuptools Found existing installation: setuptools 80.9.0 Uninstalling setuptools-80.9.0: Successfully uninstalled setuptools-80.9.0 Successfully installed setuptools-80.9.0 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 7. 重新验证环境(确保插件在升级后仍有效) PS C:\Users\Administrator\Desktop> Test-FullEnvironment -PythonPath "E:\Python310" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile ModelScope: 1.29.0 ✅ Environment has no warnings ⚠️ Found .pth file: E:\Python310\Lib\site-packages\distutils-precedence.pth File "<string>", line 9 print(fPlugin ^ SyntaxError: '(' was never closed PS C:\Users\Administrator\Desktop>
最新发布
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值