From an OS package

Python-evdev has been packaged for the following distributions:

Packaging status

Consult the documentation of your OS package manager for installation instructions.

From source

The latest stable version of python-evdev can be installed from pypi, provided that you have a compiler, pip and the Python and Linux development headers installed on your system. Installing these is distribution specific and typically falls into one of the following:

On a Debian compatible OS:

$ apt install python-dev python-pip gcc
$ apt install linux-headers-$(uname -r)

On a Redhat compatible OS:

$ dnf install python-devel python-pip gcc
$ dnf install kernel-headers-$(uname -r)

On Arch Linux and derivatives:

$ pacman -S core/linux-api-headers python-pip gcc

Once all OS dependencies are available, you may install python-evdev using pip, preferably in a [virtualenv]:

# Install globally (not recommended).
$ sudo python3 -m pip install evdev

# Install for the current user.
$ python3 -m pip install --user evdev

# Install in a virtual environment.
$ python3 -m venv abc
$ source abc/bin/activate
$ python3 -m pip install evdev

Specifying header locations

By default, the setup script will look for the input.h and input-event-codes.h [1] header files /usr/include/linux.

You may use the --evdev-headers option to the build_ext setuptools command to the location of these header files. It accepts one or more colon-separated paths. For example:

$ python setup.py build_ext \
    --evdev-headers buildroot/input.h:buildroot/input-event-codes.h \
    --include-dirs  buildroot/ \
    install  # or any other command (e.g. develop, bdist, bdist_wheel)

From a binary package

You may choose to install a precompiled version of python-evdev from pypi. The evdev-binary package provides binary wheels that have been compiled on EL8 against the 4.18.0 kernel headers.

$ python3 -m pip install evdev-binary

While the evdev interface is stable, the precompiled version may not be fully compatible or expose all the features of your running kernel. For best results, it is recommended to use an OS package or to install from source.