LPHK
LPHK copied to clipboard
You must be root to use this library on linux when using the default layout's volume function on Arch
The basic steps to the error where:
- Installing using the beta installer
- Changing the env to the LPHK env
- Running LPHK.py (with plugged in launchpad)
- Loading the default example layout
The following error occurs when i press the left, light up and down keys:
[scripts] (2, 0) Starting asynchronous script in background...
[scripts] (2, 0) Now running script...
[scripts] (2, 0) Simple keybind: prev_track
Exception in thread Thread-67637:
Traceback (most recent call last):
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/tmp/LPHK-master/scripts.py", line 523, in run_script
idx = main_logic(idx)
File "/tmp/LPHK-master/scripts.py", line 492, in main_logic
kb.press(key)
File "/tmp/LPHK-master/kb.py", line 23, in press
keyboard.press(key)
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/__init__.py", line 396, in press
send(hotkey, True, False)
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/__init__.py", line 383, in send
_os_keyboard.press(scan_codes[0])
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 158, in press
write_event(scan_code, True)
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 144, in write_event
build_device()
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
Trying to start LPHK with sudo brings a whole other problem along (tried it as suggested by @nimaid ):
(LPHK) [MYUSER@HOSTNAME LPHK-master]$ sudo /home/MYUSER/.conda/envs/LPHK/bin/python /tmp/LPHK-master/LPHK.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Traceback (most recent call last):
File "/tmp/LPHK-master/LPHK.py", line 58, in <module>
main()
File "/tmp/LPHK-master/LPHK.py", line 53, in main
init()
File "/tmp/LPHK-master/LPHK.py", line 33, in init
sound.init(PATH)
File "/tmp/LPHK-master/sound.py", line 16, in init
m.init()
pygame.error: No available audio device
My setup is:
- Laptop running Arch Linux
- I use i3 as my window-manager
- I have alsamixer and pulseaudio installed for everything related to audio i/o
- Launchpad MK2
- The LPHK installation is located in /tmp/LPHK-master
- I have sudo rights
Please comment if additional information is needed - I'll try to respond asap.
@Niggl1999 Please try running with sudo -u [YOUR-USERNAME] python LPHK.py
and report back.
First: Sorry for answering with such a huge delay.
Onto the topic: I updated to the newest version of LPHK via the linux beta installation script. And then followed your request for starting as my own user via sudo:
sudo -u niggl python Downloads/LPHK-master/LPHK.py
ALSA lib confmisc.c:767:(parse_card) cannot find card 'CODEC'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such device
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such device
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such device
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM sysdefault
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "Downloads/LPHK-master/LPHK.py", line 58, in <module>
main()
File "Downloads/LPHK-master/LPHK.py", line 53, in main
init()
File "Downloads/LPHK-master/LPHK.py", line 33, in init
sound.init(PATH)
File "/home/niggl/Downloads/LPHK-master/sound.py", line 16, in init
m.init()
pygame.error: No available audio device
@Niggl1999 Apparently there is no way around the fact that keyboard
and pynput
don't work outside of root. However, in root, usually either the display device, audio device, or both are unavailable.
I am pretty happy with the Windows version now, so I am currently developing the Linux version. If anyone has any ideas, let me know. Otherwise, I'll update you when I figure something out.
EDIT: FYI I added more elegant error handling and logging in the newest release, I would suggest using that so the program crashes less.
For unrelated reasons, I have decided to move from the keyboard
library to the pyautogui
library. keyboard
explicitly states root requirements for Linux, but pyautogui
doesn't mention it. Here's to hoping it fixes it!
I'm hoping this will fix many issues, including #7 , and perhaps #16 as well (if it isn't just a single-user issue). I am not certain if #11 is related, but I suspect the library switch will probably fix it as well.