Registry / devops / gpiozero

gpiozero

JSON →
library2.0.1pypypi✓ verified 84d ago

GPIO Zero is a Python library that provides a simple and approachable interface to GPIO (General Purpose Input/Output) devices on Raspberry Pi. It abstracts away low-level pin details, offering high-level classes for common components like LEDs, buttons, motors, and sensors, making physical computing accessible. The current version is 2.0.1. It generally follows a release cadence tied to bug fixes and new features, with major versions introducing breaking changes.

pip install gpiozero
INSTALL
IMPORT
SIG · GPIOZERO
G
gpiozero
devopspythonv2.0.1
Install
2.0s avg
Import
202ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.209s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.0s · import 0.196s · 20MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LED
from gpiozero import LED
Button
from gpiozero import Button
gpiozero (full import)
import gpiozero
RPi.GPIO (common mistake)
import RPi.GPIO
gpiozero is a higher-level abstraction; RPi.GPIO is an underlying library with a different API. Do not mix their usage without understanding pin factories.

This quickstart code demonstrates how to make an LED connected to GPIO pin 17 blink. The `pause()` function keeps the script running indefinitely, allowing the LED to continue blinking.

from gpiozero import LED from signal import pause # Replace 17 with your actual GPIO pin number (BCM numbering) led = LED(17) led.blink() pause()
Debug
Known issues
breakingPython 2.x support was removed in GPIO Zero 2.0. The minimum supported Python version is now 3.9.
fix
Migrate your code to Python 3.9 or newer. Ensure your environment uses Python 3.
affects: 2.0.0+
breakingThe `Robot` class constructor API changed in 2.0. It now expects `Motor` or `PhaseEnableMotor` instances, not tuples of pin numbers.
fix
Pass initialized `Motor` or `PhaseEnableMotor` objects to the `Robot` constructor. The old tuple-based method is deprecated and will be removed.
affects: 2.0.0+
breakingThe default pin factory changed from `RPiGPIOFactory` to `LGPIOFactory` in version 2.0. This might affect advanced users relying on specific underlying pin library behaviors.
fix
If your project relies on the previous default, explicitly set `GPIOZERO_PIN_FACTORY=rpigpio` as an environment variable or set it in your code using `gpiozero.Device.pin_factory = 'rpigpio'`.
affects: 2.0.0+
gotchaNaming your Python script `gpiozero.py` will cause an `ImportError` or unexpected behavior because Python will try to import your script instead of the installed library.
fix
Rename your script to anything other than `gpiozero.py` (e.g., `my_gpio_project.py`).
affects: All
gotchaAssigning the *result* of a function call to an event handler (e.g., `button.when_pressed = my_function()`) instead of the function itself (`button.when_pressed = my_function`) will prevent the handler from being called.
fix
Always assign the function object, not its return value, to event handlers: `button.when_pressed = my_function`.
affects: All
Errors
Common errors & fixes
Traceback (most recent call last): File "gpiozero.py", line 1, in <module> from gpiozero import LED ImportError: cannot import name 'LED' from 'gpiozero' (/path/to/your/gpiozero.py)
You have named your Python script 'gpiozero.py', causing Python to try and import your own script instead of the actual gpiozero library.
fix
Rename your script file to something different, like `my_project.py` or `led_blink.py`.
RuntimeError: Failed to add edge detection. (or similar 'GPIO Busy' error)
The GPIO pin you are trying to use is currently in use by another program or a previous script did not properly clean up its GPIO usage.
fix
Ensure all previous scripts using GPIO have terminated cleanly. You can also explicitly close devices with `device.close()`. If the issue persists, reboot your Raspberry Pi.
AttributeError: 'Button' object has no attribute 'pressed'
You are trying to access a non-existent attribute. Event handlers are typically set via `when_pressed` (a property for assigning a callback), not directly accessed as `pressed`.
fix
Use the correct event handler property, for example, `button.when_pressed = my_callback_function` to assign a function to be called when the button is pressed. If you intended to check the state, use `button.is_pressed`.
Upgrade
Version history
2.0.1latest on PyPI · released Feb 15, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
gpiozero — pip install gpiozero · libregistry