tinaheidinger
tinaheidinger

Reputation: 954

Python Mido library example does not work

I installed mido with pip install mido and tried to execute the example code from the docs:

import mido

with mido.open_input('SH-201') as inport:
    for message in inport:
        print(message)

But I get the following error message:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libportmidi.dylib, 6): image not found

Any idea what I did wrong?

Edit: Is there any other comfortable way to read input from a MIDI device with python?

Upvotes: 0

Views: 1661

Answers (1)

hoechenberger
hoechenberger

Reputation: 343

You need to install a backend that interfaces with the MIDI hardware, like PortMidi. The error message tells you that the backend was not found.

You can install it via Homebrew. In a Terminal, run:

ruby -e "$(curl -fsSL   https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

to install Homebrew. Then, run

brew install portmidi

to install PortMidi.

Download the pmdefaults Mac binary, connect your MIDI device to your computer, and run pmdefaults (right-click, select Open, since the application is not signed). Select your default MIDI device, click Update Preferences, and quit the application. Start a new Python interpreter. Mido should now work as intended.

Upvotes: 1

Related Questions