Skip to content

Commit

Permalink
Append /usr/local/lib to sys.path if import fails (#1027)
Browse files Browse the repository at this point in the history
* Append /usr/local/lib to sys.path if import fails
* update other distros installation steps
* update ubuntu link
* update issue template for autoload problems
  • Loading branch information
sezanzeb authored Jan 5, 2025
1 parent c9de7ef commit f859e91
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/autoloading-not-working.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```

23 changes: 23 additions & 0 deletions bin/input-remapper-control
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion inputremapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f859e91

Please sign in to comment.