Почему при использовании keybind возникла ошибка «Нет модуля с именем ‘fcntl'»?

#python-3.x

#python-3.x

Вопрос:

Я хочу привязать горячие клавиши к функциям в коде python, поэтому я установил keybind , но возникает ошибка. Как это исправить?

Код

     from keybind import KeyBinder
    import time

    def pr():
        print('yeh')

    KeyBinder.activate({'Ctrl-C': pr}, run_thread = True)

    while True:
        print(1)
        time.sleep(1)
 

Тогда ошибка

     Traceback (most recent call last):
      File "C:UsersIdensasPycharmProjectsprotestZEMPTY.py", line 6, in <module>
        KeyBinder.activate({'Ctrl-C':pr},run_thread=True)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-packageskeybindbinder.py", line 85, in activate
        binder = cls(keymap=keymap, listen_events=listen_events)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-        packageskeybindbinder.py", line 63, in __init__
        self.disp = Display()
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-packagesXlibdisplay.py", line 89, in __init__
        self.display = _BaseDisplay(display)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-packagesXlibdisplay.py", line 71, in __init__
        protocol_display.Display.__init__(self, *args, **keys)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-        packagesXlibprotocoldisplay.py", line 84, in __init__
        name, protocol, host, displayno, screenno = connect.get_display(display)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-        packagesXlibsupportconnect.py", line 72, in get_display
        mod = _relative_import(modname)
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-        packagesXlibsupportconnect.py", line 55, in _relative_import
        return importlib.import_module('..'   modname, __name__)
      File         "C:UsersIdensasAppDataLocalProgramsPythonPython39libimportlib__init__.py", line 127, in         import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 790, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "C:UsersIdensasAppDataLocalProgramsPythonPython39libsite-        packagesXlibsupportunix_connect.py", line 31, in <module>
        import fcntl
      ModuleNotFoundError: No module named 'fcntl'
 

Ответ №1:

fcntl это механизм в Linux, а не в системах Windows.

Из keybind документации:

Requires X11 (X Window System). For UNIX-like systems, e.g. Linux.

https://pypi.org/project/keybind/

Поэтому вам понадобится другая библиотека для систем Windows.