{"id":24459,"library":"python-rtmidi","title":"python-rtmidi","description":"Python bindings for the RtMidi C++ library, providing real-time MIDI input/output using Cython. Current version 1.5.8, updates irregularly.","status":"active","version":"1.5.8","language":"python","source_language":"en","source_url":"https://github.com/SpotlightKid/python-rtmidi","tags":["midi","music","real-time","audio"],"install":[{"cmd":"pip install python-rtmidi","lang":"bash","label":"Default install"},{"cmd":"pip install python-rtmidi[alsa]","lang":"bash","label":"With ALSA support on Linux"}],"dependencies":[],"imports":[{"note":"Old import path from version <1.0","wrong":"from rtmidi.midi import MidiIn","symbol":"MidiIn","correct":"from rtmidi import MidiIn"},{"note":"Old import path from version <1.0","wrong":"from rtmidi.midi import MidiOut","symbol":"MidiOut","correct":"from rtmidi import MidiOut"}],"quickstart":{"code":"from rtmidi import MidiIn, MidiOut\n\n# List available ports\nmidi_in = MidiIn()\nprint('Input ports:', midi_in.get_ports())\n\nmidi_out = MidiOut()\nprint('Output ports:', midi_out.get_ports())\n\n# Open first port and listen\nif midi_in.get_ports():\n    midi_in.open_port(0)\n    # Callback example\n    def callback(message, data):\n        print(message)\n    midi_in.set_callback(callback)\n    import time\n    time.sleep(2)\n    midi_in.close_port()\nelse:\n    print('No MIDI input ports found.')","lang":"python","description":"Basic setup: list ports, open input, set callback."},"warnings":[{"fix":"Install ALSA development libraries (e.g., libasound2-dev on Debian) or use system package manager.","message":"In version 1.5.8, Linux wheels no longer bundle libasound. If ALSA is not installed, the module will fail to load.","severity":"breaking","affected_versions":">=1.5.8"},{"fix":"Use threading.Lock or restrict calls to a single thread.","message":"MidiIn and MidiOut objects are not thread-safe. Do not call methods from multiple threads without external locking.","severity":"gotcha","affected_versions":"all"},{"fix":"Check your installation with `import rtmidi; print(rtmidi.get_api())`.","message":"On macOS, the library defaults to CoreMIDI but can be built with JACK. Ensure you have the correct backend installed.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `get_ports()` methods on MidiIn/MidiOut instead.","message":"The `midiutils` module is deprecated and may be removed in a future version.","severity":"deprecated","affected_versions":">=1.5.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install ALSA development libraries: `sudo apt-get install libasound2-dev` on Debian/Ubuntu.","cause":"Linux wheel does not bundle ALSA libraries starting version 1.5.8.","error":"ImportError: libasound.so.2: cannot open shared object file: No such file or directory"},{"fix":"Run `pip install python-rtmidi` and ensure you are in the correct environment.","cause":"Package not installed or virtual environment not activated.","error":"ModuleNotFoundError: No module named 'rtmidi'"},{"fix":"Use `from rtmidi import MidiIn`.","cause":"Using old import path from version <1.0.","error":"ImportError: cannot import name 'MidiIn' from 'rtmidi.midi'"},{"fix":"Check number of ports with `midi_in.get_ports()` before opening.","cause":"Port index exceeds number of available ports.","error":"ValueError: Port index out of range"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}