importError: no module named _winreg

博客指出在Python3中,某个module改名为winreg,聚焦于Python3版本下模块名称的变更这一信息技术相关内容。

因为在python3中,这个module改名为winreg了

PowerShell 7 环境已加载 (版本: 7.5.2) PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> pip install pylint Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting pylint Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/1a/711e93a7ab6c392e349428ea56e794a3902bb4e0284c1997cff2d7efdbc1/pylint-3.3.8-py3-none-any.whl (523 kB) Collecting astroid<=3.4.0.dev0,>=3.3.8 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/af/0f/3b8fdc946b4d9cc8cc1e8af42c4e409468c84441b933d037e101b3d72d86/astroid-3.3.11-py3-none-any.whl (275 kB) Requirement already satisfied: colorama>=0.4.5 in e:\python310\lib\site-packages (from pylint) (0.4.6) Collecting dill>=0.2 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/50/3d/9373ad9c56321fdab5b41197068e1d8c25883b3fea29dd361f9b55116869/dill-0.4.0-py3-none-any.whl (119 kB) Collecting isort!=5.13,<7,>=4.2.5 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c1/11/114d0a5f4dabbdcedc1125dee0888514c3c3b16d3e9facad87ed96fad97c/isort-6.0.1-py3-none-any.whl (94 kB) Collecting mccabe<0.8,>=0.6 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/1a/1f68f9ba0c207934b35b86a8ca3aad8395a3d6dd7921c0686e23853ff5a9/mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB) Requirement already satisfied: platformdirs>=2.2 in e:\python310\lib\site-packages (from pylint) (4.3.8) Collecting tomli>=1.1 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl (14 kB) Collecting tomlkit>=0.10.1 (from pylint) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bd/75/8539d011f6be8e29f339c42e633aae3cb73bffa95dd0f9adec09b9c58e85/tomlkit-0.13.3-py3-none-any.whl (38 kB) Requirement already satisfied: typing-extensions>=4 in e:\python310\lib\site-packages (from astroid<=3.4.0.dev0,>=3.3.8->pylint) (4.14.1) Installing collected packages: tomlkit, tomli, mccabe, isort, dill, astroid, pylint Successfully installed astroid-3.3.11 dill-0.4.0 isort-6.0.1 mccabe-0.7.0 pylint-3.3.8 tomli-2.2.1 tomlkit-0.13.3 PS C:\Users\Administrator\Desktop> pylint hardware_monitor.py ************* Module hardware_monitor.py hardware_monitor.py:1:0: F0001: No module named hardware_monitor.py (fatal) PS C:\Users\Administrator\Desktop> # test_hardware_monitor_unit.py PS C:\Users\Administrator\Desktop> import unittest 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> from unittest.mock import patch, MagicMock ParserError: Line | 1 | from unittest.mock import patch, MagicMock | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator\Desktop> from hardware_monitor import HardwareMonitor ParserError: Line | 1 | from hardware_monitor import HardwareMonitor | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> class TestHardwareMonitor(unittest.TestCase): ParserError: Line | 1 | class TestHardwareMonitor(unittest.TestCase): | ~ | Missing 'class' body in 'class' declaration. PS C:\Users\Administrator\Desktop> def setUp(self): self: The term 'self' 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> self.monitor = HardwareMonitor(update_interval=0.1) update_interval=0.1: The term 'update_interval=0.1' 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> def test_monitor_thread_start(self): self: The term 'self' 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> with patch.object(self.monitor, '_monitor_loop') as mock_loop: ParserError: Line | 1 | with patch.object(self.monitor, '_monitor_loop') as mock_loop … | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> self.assertTrue(self.monitor.start()) ParserError: Line | 1 | self.assertTrue(self.monitor.start()) | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> self.assertTrue(self.monitor.running) self.monitor.running: The term 'self.monitor.running' 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> self.assertTrue(self.monitor.stop()) ParserError: Line | 1 | self.assertTrue(self.monitor.stop()) | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> self.assertFalse(self.monitor.running) self.monitor.running: The term 'self.monitor.running' 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> def test_temperature_backup(self): self: The term 'self' 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> with patch('psutil.sensors_temperatures', return_value=None): ParserError: Line | 1 | with patch('psutil.sensors_temperatures', return_value=None): | ~ | Missing expression after ','. PS C:\Users\Administrator\Desktop> temp = self.monitor._get_cpu_temperature_backup() ParserError: Line | 1 | temp = self.monitor._get_cpu_temperature_backup() | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> self.assertIsInstance(temp, float) ParserError: Line | 1 | self.assertIsInstance(temp, float) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> self.assertGreater(temp, 0) ParserError: Line | 1 | self.assertGreater(temp, 0) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> def test_fan_speed_backup(self): self: The term 'self' 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> speed = self.monitor._get_fan_speed_backup() ParserError: Line | 1 | speed = self.monitor._get_fan_speed_backup() | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> self.assertIsInstance(speed, int) ParserError: Line | 1 | self.assertIsInstance(speed, int) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> self.assertGreater(speed, 0) ParserError: Line | 1 | self.assertGreater(speed, 0) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> if __name__ == "__main__": ParserError: Line | 1 | if __name__ == "__main__": | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> unittest.main() ParserError: Line | 1 | unittest.main() | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> # .pre-commit-config.yaml PS C:\Users\Administrator\Desktop> repos: repos:: The term 'repos:' 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> - repo: https://github.com/pre-commit/pre-commit-hooks ParserError: Line | 1 | - repo: https://github.com/pre-commit/pre-commit-hooks | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> rev: v4.3.0 rev:: The term 'rev:' 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> hooks: hooks:: The term 'hooks:' 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> - id: trailing-whitespace ParserError: Line | 1 | - id: trailing-whitespace | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> - id: end-of-file-fixer ParserError: Line | 1 | - id: end-of-file-fixer | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> - id: check-yaml ParserError: Line | 1 | - id: check-yaml | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> - id: check-added-large-files ParserError: Line | 1 | - id: check-added-large-files | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> - repo: https://github.com/psf/black ParserError: Line | 1 | - repo: https://github.com/psf/black | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> rev: 22.10.0 rev:: The term 'rev:' 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> hooks: hooks:: The term 'hooks:' 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> - id: black ParserError: Line | 1 | - id: black | ~ | Missing expression after unary operator '-'. PS C:\Users\Administrator\Desktop> # 在关键方法开头添加日志 PS C:\Users\Administrator\Desktop> def _monitor_loop(self): self: The term 'self' 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> self.logger.debug("Starting monitor loop") self.logger.debug: The term 'self.logger.debug' 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> try: try:: The term 'try:' 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> except Exception as e: except: The term 'except' 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> self.logger.error(f"Monitor loop failed: {e}", exc_info=True) ParserError: Line | 1 | self.logger.error(f"Monitor loop failed: {e}", exc_info=True) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> cd E:\AI_System\monitoring PS E:\AI_System\monitoring> python test_hardware_monitor.py 2025-08-23 23:40:29 - TestMonitor - INFO - 🚀 开始测试硬件监控模块 2025-08-23 23:40:29 - HardwareMonitor - INFO - ✅ 智能硬件监控模块初始化完成 2025-08-23 23:40:31 - HardwareMonitor - WARNING - ⚠️ OpenHardwareMonitor未运行或不可访问 2025-08-23 23:40:31 - HardwareMonitor - ERROR - ❌ COM组件卸载失败: name 'self极' is not defined 2025-08-23 23:40:31 - HardwareMonitor - INFO - 📖 已加载 32 条历史数据 2025-08-23 23:40:31 - HardwareMonitor - WARNING - ⚠️ 未找到SpeedFan安装路径 2025-08-23 23:40:31 - HardwareMonitor - INFO - 🚀 硬件监控已启动 2025-08-23 23:40:31 - TestMonitor - INFO - 🔧 第一阶段:基本监控测试 2025-08-23 23:40:31 - TestMonitor - INFO - 监控状态: running 2025-08-23 23:40:31 - TestMonitor - INFO - CPU: 7.6% | 内存: 34.5% | 温度: 54.7°C | 风扇: 1437 RPM 2025-08-23 23:40:32 - TestMonitor - INFO - 监控状态: running 2025-08-23 23:40:32 - TestMonitor - INFO - CPU: 7.6% | 内存: 34.5% | 温度: 54.7°C | 风扇: 1437 RPM 2025-08-23 23:40:33 - TestMonitor - INFO - 监控状态: running 2025-08-23 23:40:33 - TestMonitor - INFO - CPU: 2.1% | 内存: 34.5% | 温度: 75.7°C | 风扇: 1118 RPM 2025-08-23 23:40:34 - TestMonitor - INFO - 监控状态: running 2025-08-23 23:40:34 - TestMonitor - INFO - CPU: 2.3% | 内存: 34.5% | 温度: 74.7°C | 风扇: 963 RPM 2025-08-23 23:40:35 - TestMonitor - INFO - 监控状态: running 2025-08-23 23:40:35 - TestMonitor - INFO - CPU: 1.5% | 内存: 34.5% | 温度: 44.5°C | 风扇: 914 RPM 2025-08-23 23:40:36 - TestMonitor - INFO - 🛠️ 第二阶段:工具箱功能测试 2025-08-23 23:40:36 - TestMonitor - INFO - 🖥️ 硬件信息: Win32 exception occurred releasing IUnknown at 0x0000021F46B613B0 Win32 exception occurred releasing IUnknown at 0x0000021F46A78D30 Win32 exception occurred releasing IUnknown at 0x0000021F46A77B10 Win32 exception occurred releasing IUnknown at 0x0000021F46A79690 Win32 exception occurred releasing IUnknown at 0x0000021F46A77D90 Win32 exception occurred releasing IUnknown at 0x0000021F46A780B0 Win32 exception occurred releasing IUnknown at 0x0000021F46B62A30 Win32 exception occurred releasing IUnknown at 0x0000021F46A78A10 Win32 exception occurred releasing IUnknown at 0x0000021F46A795F0 Win32 exception occurred releasing IUnknown at 0x0000021F46A79050 Win32 exception occurred releasing IUnknown at 0x0000021F46B61530 Win32 exception occurred releasing IUnknown at 0x0000021F46A794B0 Win32 exception occurred releasing IUnknown at 0x0000021F46A785B0 Win32 exception occurred releasing IUnknown at 0x0000021F46A77C50 2025-08-23 23:40:37 - TestMonitor - INFO - CPU: Intel(R) Core(TM) i5-14600KF 2025-08-23 23:40:37 - TestMonitor - INFO - 内存: 2 条 2025-08-23 23:40:37 - TestMonitor - INFO - 磁盘: 4 个 2025-08-23 23:40:37 - TestMonitor - INFO - 显卡: NVIDIA GeForce RTX 5070 2025-08-23 23:40:37 - TestMonitor - INFO - ⚙️ CPU工具: 2025-08-23 23:40:37 - TestMonitor - INFO - - CPU压力测试: 运行CPU压力测试 2025-08-23 23:40:37 - TestMonitor - INFO - - CPU性能分析: 分析CPU性能瓶颈 2025-08-23 23:40:37 - TestMonitor - INFO - - CPU温度监控: 实时监控CPU温度 2025-08-23 23:40:37 - TestMonitor - INFO - - CPU频率调整: 调整CPU工作频率 2025-08-23 23:40:37 - TestMonitor - INFO - 🌡️ 温度监控: 2025-08-23 23:40:37 - TestMonitor - INFO - 当前温度: 63.1°C 2025-08-23 23:40:37 - TestMonitor - INFO - 历史记录数: 22 2025-08-23 23:40:37 - TestMonitor - INFO - 🌀 风扇控制: 2025-08-23 23:40:37 - TestMonitor - INFO - 当前风扇转速: 1130 RPM 2025-08-23 23:40:37 - TestMonitor - INFO - 当前模式: balanced 2025-08-23 23:40:37 - TestMonitor - INFO - 📊 第三阶段:历史数据测试 2025-08-23 23:40:37 - TestMonitor - INFO - 获取到 22 条历史记录 2025-08-23 23:40:37 - TestMonitor - INFO - 最新记录: CPU=3.2% 温度=63.1°C 2025-08-23 23:40:37 - HardwareMonitor - ERROR - ❌ COM组件卸载失败: name 'self极' is not defined 2025-08-23 23:40:37 - HardwareMonitor - INFO - 💾 已保存 39 条历史数据 2025-08-23 23:40:37 - HardwareMonitor - INFO - 🛑 硬件监控已停止 2025-08-23 23:40:37 - TestMonitor - INFO - 🛑 硬件监控器已停止 2025-08-23 23:40:37 - TestMonitor - INFO - ✅ 测试完成 Win32 exception occurred releasing IUnknown at 0x0000021F46B55B90 Win32 exception occurred releasing IUnknown at 0x0000021F46B61130 Win32 exception occurred releasing IUnknown at 0x0000021F46B628B0 Win32 exception occurred releasing IUnknown at 0x0000021F46B55FB0 Win32 exception occurred releasing IUnknown at 0x0000021F46B629B0 Win32 exception occurred releasing IUnknown at 0x0000021F46B62830 Win32 exception occurred releasing IUnknown at 0x0000021F468C4420 PS E:\AI_System\monitoring> PS E:\AI_System\monitoring>
最新发布
08-24
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值