Piano Hat Midi on Raspberry Pi 3

I can’t get the midi-piano.py example script to work on my new Raspberry Pi 3. It worked fine on a Raspberry Pi 2 and I followed the same procedure to install the midi library on the Pi 3 but it doesn’t work. I don’t get any errors when I run the setup script for the library but when I run midi-piano.py it gets an error on the statement import midi.sequencer saying there is no module called sequencer. I get the same error with the mididumphw.py script that is included with the library. I can import midi so it looks as if the library has installed, but I can’t import midi.sequencer

I am using the version of Linux installed on the SD card that Pimoroni sell with their Raspberry Pi 3 essentials kit.

Is there any way to fix this or is the midi library not compatible with the Raspberry Pi 3?

no, this has nothing to do with compatibility with Raspberry Pi 3… I tried it on a clean Jessie install and at first got the same issue on a Pi 2.

if you check the setup.py file in the python-midi repo you can see that it’s looking for ALSA headers, so just run:

sudo apt-get install libasound2-dev swig

then remove the version you installed previously using:

sudo pip uninstall midi

last, clean rebuild/install python-midi using the setup file.
It should work then.

The midi library must be compatible, there’s no earthly reason why it wouldn’t be. So I suspect it’s something else afoot.

On your Pi 2 setup, what happens if you type:

pip freeze | grep midi

Versus on your Pi 2.

It might be a conflicting midi package, like python-midi, installed which also uses the “midi” module name. So the fix might be:

sudo pip uninstall python-midi

Edit: @RogueM beat me to it :D Above speculative debugging left in for posterity. And just in case it’s somehow useful.

Thanks RogueM, the sudo pip uninstall midi followed by the re-install fixed it.