From ad07048f72be5ed8c9dbbbef9524239261d15c4b Mon Sep 17 00:00:00 2001 From: "A.Shpak" Date: Sun, 15 Feb 2026 12:48:20 +0300 Subject: [PATCH] fix: clear error when winreg is missing and document Windows-only in README --- README.md | 4 +++- winregistry.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6268089..ad0e3bc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ [![PyPI](https://img.shields.io/pypi/v/winregistry.svg)](https://pypi.python.org/pypi/winregistry) [![PyPI](https://img.shields.io/pypi/dm/winregistry.svg)](https://pypi.python.org/pypi/winregistry) -A Python library for interacting with the Windows registry. This library provides a simple and intuitive API for performing common registry operations, making it easier to work with the Windows registry in Python applications and automated tests. +A Python library for interacting with the Windows registry. + +**Windows only.** This library depends on the standard library module `winreg`, which is available only on Windows. On Linux or macOS you will get `ModuleNotFoundError: No module named 'winreg'`; use Windows or guard usage with a platform check (e.g. `if sys.platform == "win32"`). This library provides a simple and intuitive API for performing common registry operations, making it easier to work with the Windows registry in Python applications and automated tests. ## Installation diff --git a/winregistry.py b/winregistry.py index d344bd7..3bb0143 100644 --- a/winregistry.py +++ b/winregistry.py @@ -7,7 +7,16 @@ URL: https://github.com/shpaker/winregistry """ -import winreg +import sys + +try: + import winreg +except ImportError as e: + raise ImportError( + "winregistry requires Windows. The 'winreg' module is part of the Python " + "standard library only on Windows. Current platform: {!r}".format(sys.platform) + ) from e + from abc import ABC, abstractmethod from collections import namedtuple from contextlib import contextmanager