I used pip install evdev to install evdev in a conda env installed on Ubuntu. But it gives the following error.
In file included from /nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/Python.h:91,
from src/evdev/ecodes.c:1:
src/evdev/ecodes.c: In function ‘PyInit__ecodes’:
src/evdev/ecodes.c:542:29: error: ‘KEY_LINK_PHONE’ undeclared (first use in this function); did you mean ‘KEY_PICKUP_PHONE’?
542 | PyModule_AddIntMacro(m, KEY_LINK_PHONE);
| ^~~~~~~~~~~~~~
/nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/modsupport.h:63:67: note: in definition of macro ‘PyModule_AddIntMacro’
63 | #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
| ^
src/evdev/ecodes.c:542:29: note: each undeclared identifier is reported only once for each function it appears in
542 | PyModule_AddIntMacro(m, KEY_LINK_PHONE);
| ^~~~~~~~~~~~~~
/nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/modsupport.h:63:67: note: in definition of macro ‘PyModule_AddIntMacro’
63 | #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
| ^
src/evdev/ecodes.c:616:29: error: ‘KEY_REFRESH_RATE_TOGGLE’ undeclared (first use in this function)
616 | PyModule_AddIntMacro(m, KEY_REFRESH_RATE_TOGGLE);
| ^~~~~~~~~~~~~~~~~~~~~~~
/nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/modsupport.h:63:67: note: in definition of macro ‘PyModule_AddIntMacro’
63 | #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
| ^
src/evdev/ecodes.c:631:29: error: ‘KEY_ACCESSIBILITY’ undeclared (first use in this function)
631 | PyModule_AddIntMacro(m, KEY_ACCESSIBILITY);
| ^~~~~~~~~~~~~~~~~
/nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/modsupport.h:63:67: note: in definition of macro ‘PyModule_AddIntMacro’
63 | #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
| ^
src/evdev/ecodes.c:632:29: error: ‘KEY_DO_NOT_DISTURB’ undeclared (first use in this function)
632 | PyModule_AddIntMacro(m, KEY_DO_NOT_DISTURB);
| ^~~~~~~~~~~~~~~~~~
/nvme-ssd1/wuwenqiang/nvme-ssd1/wuwenqiang/envs/human_policy/include/python3.11/modsupport.h:63:67: note: in definition of macro ‘PyModule_AddIntMacro’
63 | #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
| ^
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for evdev
Failed to build evdev
error: failed-wheel-build-for-install×ばつ Failed to build installable wheels for some pyproject.toml based projects
I tried to add gcc to environment path but didn't work. And I checked the gcc path. It uses the system compiler. Is there anyone know how to solve it?
-
3Looks like github.com/gvalkov/python-evdev/issues/166user16540390– user165403902025年08月06日 09:55:12 +00:00Commented Aug 6, 2025 at 9:55
2 Answers 2
To avoid making changes in system files you can download package from PyPI. Then you are able to comment lines that causes error, and build package from file.
Steps to solve
- Open PyPI and download archive with package
- Extract folder from archive to any known place
- Open file src/evdev/ecodes.c
- Comment line 542
[...]
PyModule_AddIntMacro(m, KEY_PICKUP_PHONE);
PyModule_AddIntMacro(m, KEY_HANGUP_PHONE);
//PyModule_AddIntMacro(m, KEY_LINK_PHONE);
PyModule_AddIntMacro(m, KEY_DEL_EOL);
PyModule_AddIntMacro(m, KEY_DEL_EOS);
[...]
- Open terminal and activate your venv (if you are using it)
- Go to folder with given package and write
pip install .
- If there are more problematic lines in ecodes.c files, comment them like in step 4
Now your package evdev should be installed without any errors.
Comments
Here are some fixes from the issue 166 on the evdev GitHub repository page.
1
brew unlink linux-headers
Which was mentioned by albertz.
2
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
Which was mentioned by syhanjin
The issue was replicated using Ubuntu22.04, Python3.10 (through conda)
Some options that probably won't work, but I mine as well put them here:
- Use a different ENV like pyenv
- Reinstall GCC / G++
Most likely won't do anything, but you never know
It does seem like the issue is mostly on Ubuntu, since users on other platforms seem to say it works fine.
PS - jabaa pointed out issue #166 in their comment on this post, I just wanted to put the info here.
EDIT
I made this while really tired, so I'm sorry if I messed some stuff up here.