SpotlightKid / python-rtmidi

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

Build failure on Windows (plus request to provide wheel packages for python 3.10) #113

Closed mojca closed 1 year ago

mojca commented 1 year ago

I'm trying to install rtmidi_python on Windows for Python 3.10 without success. It would probably help if the wheel was available out of the box.

> pip install rtmidi_python
Collecting rtmidi_python
  Using cached rtmidi-python-0.2.2.tar.gz (54 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: rtmidi_python
  Building wheel for rtmidi_python (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'rtmidi_python' extension
      creating build
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      creating build\temp.win-amd64-3.10\Release\RtMidi
      C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WINDOWS_MM__ -ID:\Path\to\venv\include -IC:\Program Files\Python310\include -IC:\Program Files\Python310\Include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\VS\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um /EHsc /TpRtMidi/RtMidi.cpp /Fobuild\temp.win-amd64-3.10\Release\RtMidi/RtMidi.obj
      RtMidi.cpp
      C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WINDOWS_MM__ -ID:\Path\to\venv\include -IC:\Program Files\Python310\include -IC:\Program Files\Python310\Include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\VS\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um /EHsc /Tprtmidi_python.cpp /Fobuild\temp.win-amd64-3.10\Release\rtmidi_python.obj
      rtmidi_python.cpp
      rtmidi_python.cpp(2557): error C2105: '++' needs l-value
      rtmidi_python.cpp(2559): error C2105: '--' needs l-value
      rtmidi_python.cpp(2654): error C2105: '++' needs l-value
      rtmidi_python.cpp(2656): error C2105: '--' needs l-value
      rtmidi_python.cpp(2932): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2941): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2950): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2966): warning C4996: 'PyEval_InitThreads': deprecated in 3.9
      rtmidi_python.cpp(3094): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      rtmidi_python.cpp(3110): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.33.31517\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for rtmidi_python
  Running setup.py clean for rtmidi_python
Failed to build rtmidi_python
Installing collected packages: rtmidi_python
  Running setup.py install for rtmidi_python ... error
  error: subprocess-exited-with-error

  × Running setup.py install for rtmidi_python did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      running install
      running build
      running build_ext
      building 'rtmidi_python' extension
      creating build
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      creating build\temp.win-amd64-3.10\Release\RtMidi
      C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WINDOWS_MM__ -ID:\Path\to\venv\include -IC:\Program Files\Python310\include -IC:\Program Files\Python310\Include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\VS\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um /EHsc /TpRtMidi/RtMidi.cpp /Fobuild\temp.win-amd64-3.10\Release\RtMidi/RtMidi.obj
      RtMidi.cpp
      C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WINDOWS_MM__ -ID:\path\to\venv\include -IC:\Program Files\Python310\include -IC:\Program Files\Python310\Include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31517\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\VS\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um /EHsc /Tprtmidi_python.cpp /Fobuild\temp.win-amd64-3.10\Release\rtmidi_python.obj
      rtmidi_python.cpp
      rtmidi_python.cpp(2557): error C2105: '++' needs l-value
      rtmidi_python.cpp(2559): error C2105: '--' needs l-value
      rtmidi_python.cpp(2654): error C2105: '++' needs l-value
      rtmidi_python.cpp(2656): error C2105: '--' needs l-value
      rtmidi_python.cpp(2932): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2941): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2950): error C2039: 'tp_print': is not a member of '_typeobject'
      C:\Program Files\Python310\include\cpython/object.h(191): note: see declaration of '_typeobject'
      rtmidi_python.cpp(2966): warning C4996: 'PyEval_InitThreads': deprecated in 3.9
      rtmidi_python.cpp(3094): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      rtmidi_python.cpp(3110): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.33.31517\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> rtmidi_python

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
mojca commented 1 year ago

Oh, I'm sorry. It looks like I'm looking at the wrong project. I thought it was weird that I didn't find the file rtmidi_python.cpp anywhere inside the sources.

I just wanted to get https://github.com/josephernest/SamplerBox working and while this project seems a lot more active than the other one (and it installs out of the box), I would need to port the code of samplerbox first if I wanted to use this one.

mojca commented 1 year ago

At least for the SamplerBox, porting the code to make it work with python-rtmidi surprisingly seemed relatively trivial. Apart from the import name (and further changes to support python 3) I needed to do just one tiny change in the source:

 midi_in = [rtmidi.MidiIn()]
 previous = []
 while True:
-    for port in midi_in[0].ports:
+    for port in midi_in[0].get_ports():
         if port not in previous and 'Midi Through' not in port:
             midi_in.append(rtmidi.MidiIn())
             midi_in[-1].callback = MidiCallback
             midi_in[-1].open_port(port)
             print('Opened MIDI:', port)
-    previous = midi_in[0].ports
+    previous = midi_in[0].get_ports()
     time.sleep(2)

Would it perhaps be possible to support the syntax .ports in addition to .get_ports() in your library? It sounds a lot more "pythonic" that way and it might make life of other ports easier at the same time.