Skip to main content
 首页 » 编程设计

python之导入python的winreg模块时出现ImportError

2025年05月04日11JeffreyZhao

我想使用 python 的 winreg 模块来处理 Windows 注册表。 但是当我尝试导入 winreg 模块时,它给出了 ImportError。

Python 2.4.3 (#1, Dec 11 2006, 11:39:03)  
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import __winreg 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
ImportError: No module named __winreg 
>>> import _winreg 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
ImportError: No module named _winreg 

我需要单独安装这个模块吗? 任何建议都会有用。

请您参考如下方法:

它不能在 Linux 上运行。

_winreg - Windows registry access

Availability: Windows.

New in version 2.0. These functions expose the Windows registry API to Python. Instead of using an integer as the registry handle, a handle object is used to ensure that the handles are closed correctly, even if the programmer neglects to explicitly close them.

This module exposes a very low-level interface to the Windows registry; it is expected that in the future a new winreg module will be created offering a higher-level interface to the registry API.

来源:http://docs.python.org/release/2.1.2/lib/module--winreg.html