From f859e91583a999cee35126b260f7dc46886f22b8 Mon Sep 17 00:00:00 2001 From: Tobi <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 5 Jan 2025 01:41:44 +0100 Subject: [PATCH] Append /usr/local/lib to sys.path if import fails (#1027) * Append /usr/local/lib to sys.path if import fails * update other distros installation steps * update ubuntu link * update issue template for autoload problems --- .../ISSUE_TEMPLATE/autoloading-not-working.md | 3 +-- README.md | 16 ++++++------- bin/input-remapper-control | 23 +++++++++++++++++++ inputremapper/groups.py | 2 +- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/autoloading-not-working.md b/.github/ISSUE_TEMPLATE/autoloading-not-working.md index ea42ed162..15596cd80 100644 --- a/.github/ISSUE_TEMPLATE/autoloading-not-working.md +++ b/.github/ISSUE_TEMPLATE/autoloading-not-working.md @@ -23,5 +23,4 @@ Please install the newest version from source to see if the problem has already 1. `input-remapper-control --command hello` 2. `sudo pkill -f input-remapper-service && sudo input-remapper-service -d & sleep 2 && input-remapper-control --command autoload`, are your keys mapped now? -3. If it still doesn't work, run (while the previous command is still running) `sudo evtest` and search for a device suffixed by "mapped". Select it, does it report any events? Share the output. -4. `sudo udevadm control --log-priority=debug && sudo udevadm control --reload-rules && journalctl -f | grep input-remapper`, now plug in the device that should autoload +3. `sudo udevadm control --log-priority=debug && sudo udevadm control --reload-rules && journalctl -f | grep input-remapper`, now plug in the device that should autoload diff --git a/README.md b/README.md index 47ad33764..2680416de 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ sudo apt install -f ./dist/input-remapper-2.0.1.deb ``` Input Remapper is also available in the repositories of [Debian](https://tracker.debian.org/pkg/input-remapper) -and [Ubuntu](https://packages.ubuntu.com/jammy/input-remapper) via +and [Ubuntu](https://packages.ubuntu.com/oracular/input-remapper) via ```bash sudo apt install input-remapper @@ -74,22 +74,20 @@ sudo systemctl enable --now input-remapper ### Other Distros Figure out the packages providing those dependencies in your distro, and install them: -`python3-evdev` ≥1.3.0, `gtksourceview4`, `python3-devel`, `python3-pydantic`, `python3-pydbus`, `python3-psutil` +`python3-evdev` ≥1.3.0, `gtksourceview4`, `python3-devel`, `python3-pydantic`, +`python3-pydbus`, `python3-psutil` -Python packages need to be installed globally for the service to be able to import them. Don't use `--user`. -Conda and such may also cause problems due to changed python paths and versions. +You can also use pip to install some of them. Python packages need to be installed +globally for the service to be able to import them. Don't use `--user`. Conda and such +may also cause problems due to changed python paths and versions. ```bash -sudo pip install --no-binary :all: git+https://github.com/sezanzeb/input-remapper.git -sudo systemctl enable --now input-remapper +sudo pip install evdev pydantic pydbus PyGObject setuptools ``` -Or, if that doesn't install it correctly, try - ```bash git clone https://github.com/sezanzeb/input-remapper.git cd input-remapper sudo python3 setup.py install sudo systemctl enable --now input-remapper ``` - diff --git a/bin/input-remapper-control b/bin/input-remapper-control index 750aca4c4..67a494817 100755 --- a/bin/input-remapper-control +++ b/bin/input-remapper-control @@ -20,6 +20,29 @@ """Control the dbus service from the command line.""" +import os +import sys + + +def fix_import_path(): + # Installations via `sudo python3 setup.py install` install into /usr/local/lib + # instead of /usr/local. sys.path is missing /usr/local/lib when udev is running + # its rules. + try: + import inputremapper + except ModuleNotFoundError: + python_folder = f"python{sys.version_info.major}.{sys.version_info.minor}" + usr_local_lib = f"/usr/local/lib/{python_folder}/dist-packages" + if not os.path.exists(usr_local_lib): + return + + print(f'Appending "{usr_local_lib}" to sys.path') + sys.path.append(usr_local_lib) + + +fix_import_path() + + from inputremapper.bin.input_remapper_control import InputRemapperControlBin if __name__ == "__main__": diff --git a/inputremapper/groups.py b/inputremapper/groups.py index ae9a86b0b..c4eacbab4 100644 --- a/inputremapper/groups.py +++ b/inputremapper/groups.py @@ -476,7 +476,7 @@ def refresh(self): self.loads(pipe[0].recv()) if len(self._groups) == 0: - logger.debug("Did not find any input device") + logger.error("Did not find any input device") else: keys = [f'"{group.key}"' for group in self._groups] logger.info("Found %s", ", ".join(keys))