obeezzy / lpminimk3

Python API for the Launchpad Mini MK3
https://pypi.org/project/lpminimk3/
MIT License
25 stars 2 forks source link

lpminimk3 not working in raspberry pi #144

Open pitzer opened 1 year ago

pitzer commented 1 year ago

I'm trying to use the Launchpad Mini MK3 on a Raspberry Pi 4 and struggle getting it to work.

Installed lpminimk3 using

$ pip install lpminimk3

Running the example gives me the following error:

$ python3 -m lpminimk3.examples.hello
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/__init__.py", line 81, in <module>
    from .device import LaunchpadMiniMk3, find_launchpads  # noqa
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/device.py", line 3, in <module>
    from rtmidi import MidiOut, MidiIn
  File "/home/pi/.local/lib/python3.9/site-packages/rtmidi/__init__.py", line 4, in <module>
    from ._rtmidi import *  # noqa
ImportError: libjack.so.0: cannot open shared object file: No such file or directory

After installing the libjack-dev dependency it seems to require a JACK server

$ python3 -m lpminimk3.examples.hello
Traceback (most recent call last):
  File "_rtmidi.pyx", line 1023, in _rtmidi.MidiOut.__cinit__
RuntimeError: MidiOutJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/examples/hello.py", line 21, in <module>
    main()
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/examples/hello.py", line 12, in main
    lp = find_launchpads()[0]  # Get the first available launchpad
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/device.py", line 314, in find_launchpads
    midi_out = MidiOut()
  File "_rtmidi.pyx", line 1025, in _rtmidi.MidiOut.__cinit__
_rtmidi.SystemError: MidiOutJack::initialize: JACK server not running?

After installing jackd and running it using

$ jackd -d alsa

Results in not finding the lp mini:

$ python3 -m lpminimk3.examples.hello
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/examples/hello.py", line 21, in <module>
    main()
  File "/home/pi/.local/lib/python3.9/site-packages/lpminimk3/examples/hello.py", line 12, in main
    lp = find_launchpads()[0]  # Get the first available launchpad
IndexError: list index out of range
obeezzy commented 1 year ago

@pitzer, when I tried building on my Raspberry Pi 4, I got a different error:

$ pip3 install lpminimk3
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting lpminimk3
  Using cached https://files.pythonhosted.org/packages/0f/61/9735eaf4d8aa6d765f5f15483ff3075df7c0799a895a96e617596a405efd/lpminimk3-0.6.2-py3-none-any.whl
Collecting python-rtmidi (from lpminimk3)
  Using cached https://files.pythonhosted.org/packages/fc/fa/9c1dd76467da143a779cc78bac7af0b03447ce18c8918f5aee306a6b3b5c/python_rtmidi-1.5.4.tar.gz
  Installing build dependencies ... done
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.7/tokenize.py", line 447, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-qocxoxvz/python-rtmidi/setup.py'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-qocxoxvz/python-rtmidi/

The error shows that python-rtmidi failed to install its build dependencies, so I tried to install it directly on the Pi and got this error:

$ pip3 install python-rtmidi
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-rtmidi
  Using cached https://files.pythonhosted.org/packages/fc/fa/9c1dd76467da143a779cc78bac7af0b03447ce18c8918f5aee306a6b3b5c/python_rtmidi-1.5.4.tar.gz
  Installing build dependencies ... done
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.7/tokenize.py", line 447, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-ueqee1do/python-rtmidi/setup.py'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-ueqee1do/python-rtmidi/

So I believe there may be an issue with python-rtmidi on Raspberry Pi 4.

But then, I tried it on a more recent Raspberry Pi 4 I have and got the following result:

$ pip3 install lpminimk3
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting lpminimk3
  Downloading https://www.piwheels.org/simple/lpminimk3/lpminimk3-0.6.2-py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 226 kB/s
Collecting jsonschema
  Downloading https://www.piwheels.org/simple/jsonschema/jsonschema-4.18.4-py3-none-any.whl (80 kB)
     |████████████████████████████████| 80 kB 457 kB/s
Collecting websockets
  Downloading websockets-11.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (130 kB)
     |████████████████████████████████| 130 kB 3.1 MB/s
Collecting python-rtmidi
  Downloading python_rtmidi-1.5.4-cp39-cp39-manylinux_2_28_aarch64.whl (728 kB)
     |████████████████████████████████| 728 kB 6.0 MB/s
Collecting jsonschema-specifications>=2023.03.6
  Downloading https://www.piwheels.org/simple/jsonschema-specifications/jsonschema_specifications-2023.7.1-py3-none-any.whl (17 kB)
Collecting attrs>=22.2.0
  Downloading https://www.piwheels.org/simple/attrs/attrs-23.1.0-py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 372 kB/s
Collecting rpds-py>=0.7.1
  Downloading rpds_py-0.9.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 6.0 MB/s
Collecting referencing>=0.28.4
  Downloading https://www.piwheels.org/simple/referencing/referencing-0.30.0-py3-none-any.whl (25 kB)
Installing collected packages: rpds-py, attrs, referencing, jsonschema-specifications, websockets, python-rtmidi, jsonschema, lpminimk3
Successfully installed attrs-23.1.0 jsonschema-4.18.4 jsonschema-specifications-2023.7.1 lpminimk3-0.6.2 python-rtmidi-1.5.4 referencing-0.30.0 rpds-py-0.9.2 websockets-11.0.3

The only difference between the two Pis are the Debian versions. The Pi that worked had this for its kernel version and distribution information respectively:

$ uname -a   # kernel version
Linux paw 6.1.21-v8+ 1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
$ lsb_release -a   # distribution information
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye

The Pi that didn't work had this:

$ uname -a   # kernel version
Linux colaj 4.19.75-v7l+ 1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux
$ lsb_release -a   # distribution information
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster

You may want to check if you have the latest version of the OS. Hope this helps.