SpotlightKid / python-rtmidi

Python bindings for the cross-platform MIDI I/O library RtMidi
https://spotlightkid.github.io/python-rtmidi/
Other
349 stars 64 forks source link

get_ports() method returns blank lists with Python 3.11 and ARM Macs #168

Closed Jasonhead44 closed 1 year ago

Jasonhead44 commented 1 year ago

python-rtmidi 1.5.3 fixed runtime errors for ARM Macs, however some methods are no longer working.

The get_ports method is returning blank lists when used with Python 3.11.4 and python-rtmidi 1.5.3, reverting back to Python 3.10 and python-midi 1.4.9 fixes this issue.

import rtmidi

mi = rtmidi.MidiIn()
mo = rtmidi.MidiOut()

print(mi.get_ports())
print(mo.get_ports())

Returns:

[]
[]

mido/mido#486

SpotlightKid commented 1 year ago

As shown in the output from

python3 -c 'import rtmidi; print(rtmidi.get_compiled_api())'
[6]

in the upstream mido ticket your installed version of python-rtmidi does not have CoreMIDI support compiled in.

Now the question is whether your installed version of python-rtmidi is the one from the binary wheels for arm64 macOS we provide on PyPI or whether it was compiled on your system.

Please use the following to de-install and re-install python-rtmidi again:

pip uninstall python-rmidi
pip -vv install -U --no-cache-dir --log install.log python-rtmidi
python -c 'import rtmidi; print(rtmidi._rtmidi.__file__); print(rtmidi.__version__); print(rtmidi.get_compiled_api())'

And post the output here and attach the install.log file.

If that works, do the same again and replace python-rtmidi with mido on the second line.

Jasonhead44 commented 1 year ago

I uninstalled python-rtmidi and reinstalled using the command:

python3 -m pip -vv install -U --no-cache-dir --log install.log python-rtmidi

I have attached the install.log file below, it appears it is from one of the binary wheels for arm64 macOS but I may be reading the log incorrectly.

I ran the following command:

python3 -c  'import rtmidi; print(rtmidi._rtmidi.__file__); print(rtmidi.__version__); print(rtmidi.c())'

With this result:

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/rtmidi/_rtmidi.cpython-311-darwin.so
1.5.3
[install.log](https://github.com/SpotlightKid/python-rtmidi/files/11876768/install.log)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'rtmidi' has no attribute 'c'

install.log

SpotlightKid commented 1 year ago

Sorry, I must have accidentally botched that command when editing it. It should be:

python -c 'import rtmidi; print(rtmidi._rtmidi.__file__); print(rtmidi.__version__); print(rtmidi.get_compiled_api())' 
Jasonhead44 commented 1 year ago

No worries, here is the correct output but still showing complied_api [6]:

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/rtmidi/_rtmidi.cpython-311-darwin.so
1.5.3
[6]
SpotlightKid commented 1 year ago

I confirm that the macOS arm64 binary wheels for the 1.5.3 release are unfortunately compiled without CoreMIDI support. Unfortunately we currently can't test these cross-compiled binary wheels in our CI.

Here's the log showing CoreMIDI is not detected correctly when cross-compiling:

https://github.com/SpotlightKid/python-rtmidi/actions/runs/5353650026/jobs/9709748875#step:4:1468

A fix is in #169.

SpotlightKid commented 1 year ago

Can you please download the file artifact.zip from here:

https://github.com/SpotlightKid/python-rtmidi/suites/13882085393/artifacts/771729250

... unpack the zip and install the file python_rtmidi-1.5.3-cp311-cp311-macosx_11_0_arm64.whl in it:

pip uninstall python-rtmidi
pip install -U python_rtmidi-1.5.3-cp311-cp311-macosx_11_0_arm64.whl

Then run:

python -c 'import rtmidi; print(rtmidi.get_compiled_api()); mo = rtmidi.MidiOut(); print(mo.get_ports())'

... and report the output or any errors here.

Jasonhead44 commented 1 year ago

Thank you very much for the quick fix, I downloaded the zip file, uninstalled python-rtmidi, reinstalled from the new Wheel file and ran the command:

python -c 'import rtmidi; print(rtmidi.get_compiled_api()); mo = rtmidi.MidiOut(); print(mo.get_ports())'

With the result:

[1]
['DeviceA']

It appears to be working as expected now! Let me know if there is any other testing you would like for me to perform.

SpotlightKid commented 1 year ago

This looks good. I don't think we need other tests.

We'll do a new fixed release asap.