smbus - Python SMBus bindings

raw JSON →
1.1.post2 verified Sat May 09 auth: no python maintenance

Python bindings for Linux SMBus access through i2c-dev. Current version 1.1.post2. Minimal maintenance, not actively developed.

pip install smbus
error ModuleNotFoundError: No module named 'smbus'
cause smbus package not installed.
fix
pip install smbus
error PermissionError: [Errno 13] Permission denied: '/dev/i2c-1'
cause User does not have access to I2C bus.
fix
Run script with sudo or add user to i2c group.
error FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
cause I2C device not enabled or incorrect bus number.
fix
Enable I2C via raspi-config or check bus number with i2cdetect -l.
gotcha smbus requires root/sudo access to /dev/i2c-* devices. Running without privileges causes PermissionError.
fix Run script with sudo or add user to i2c group: sudo usermod -aG i2c $USER
gotcha smbus is Python 2 only in older versions; version 1.1.post2 supports Python 3 but check system Python version.
fix Use smbus >=1.1 for Python 3 support, or install smbus-cffi as alternative.
deprecated smbus package is largely unmaintained; consider migrating to smbus2 or smbus-cffi for active support and Python 3 compatibility.
fix Replace import with smbus2 (from smbus2 import SMBus) for nearly identical API.

Open I2C bus 1, read one byte from register 0x00 of device at address 0x48.

from smbus import SMBus

bus = SMBus(1)  # /dev/i2c-1
address = 0x48
data = bus.read_byte_data(address, 0x00)
print(f"Read: {data}")
bus.close()