2017-07-03 26 views
0

私はPythonがキーイベントを読み込ませるようにいくつかの問題を抱えているようですが、私はこのコードを書きました 私は、それを解放してください。IOError:[Errno 1]操作が許可されていません: '/ dev/uinput'

import pyaudio 
import wave 
import keyboard 

CHUNK = 1024 
FORMAT = pyaudio.paInt16 
CHANNELS = 2 
RATE = 44100 
RECORD_SECONDS = 5 
WAVE_OUTPUT_FILENAME = "output.wav" 

p = pyaudio.PyAudio() 

stream = p.open(format=FORMAT, 
       channels=CHANNELS, 
       rate=RATE, 
       input=True, 
       frames_per_buffer=CHUNK) 

print("* recording") 

frames = [] 

while keyboard.is_pressed('space'): 
    data = stream.read(CHUNK) 
    frames.append(data) 

print("* done recording") 

stream.stop_stream() 
stream.close() 
p.terminate() 

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') 
wf.setnchannels(CHANNELS) 
wf.setsampwidth(p.get_sample_size(FORMAT)) 
wf.setframerate(RATE) 
wf.writeframes(b''.join(frames)) 
wf.close() 

しかし、このコードを実行すると、このエラーメッセージが表示されます。

python sound_record.py 
* recording 
Traceback (most recent call last): 
    File "sound_record.py", line 24, in <module> 
    while keyboard.is_pressed('space'): 
    File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 162, in is_pressed 
    _listener.start_if_necessary() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_generic.py", line 36, in start_if_necessary 
    self.init() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 112, in init 
    _os_keyboard.init() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 110, in init 
    build_device() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 106, in build_device 
    ensure_root() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 163, 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. 

とするとき、それはsudoを、私を使用してください:

sudo !! 
sudo python sound_record.py 
Password: 
* recording 
Traceback (most recent call last): 
    File "sound_record.py", line 24, in <module> 
    while keyboard.is_pressed('space'): 
    File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 162, in is_pressed 
    _listener.start_if_necessary() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_generic.py", line 36, in start_if_necessary 
    self.init() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 112, in init 
    _os_keyboard.init() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 110, in init 
    build_device() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 107, in build_device 
    device = aggregate_devices('kbd') 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 141, in aggregate_devices 
    uinput = make_uinput() 
    File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 27, in make_uinput 
    uinput = open("/dev/uinput", 'wb') 
IOError: [Errno 1] Operation not permitted: '/dev/uinput' 

、なぜ私はこのエラーメッセージを取得していますか?

答えて

1

あなたは、そのdescriptionあるPythonパッケージkeyboard、使用しているように表示されます。

Hook and simulate keyboard events on Windows and Linux

あなたはMacOSの上のキーボードイベントと仕事をしたい場合は、あなたがそれを行うパッケージを見つける必要がありますが。

関連する問題