Skip to content

pygame.midi.init() Failing on Android 4.4.4 - ImportError: No module named pypm #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leomrocha opened this issue Mar 20, 2015 · 2 comments

Comments

@leomrocha
Copy link

Hi, Trying to connect my MIDI keyboard to my Android device here and I run into some problems.

TLDR:

pygame.midi.init() launches ImportError: No module named pypm on Android 4.4.4, Kivy 1.8, buildozer 0.27dev

Index

  • Information
  • traceback
  • source code to reproduce the error
  • grep for pypm on android-for-python

PLATFORM INFORMATION

  • Kivy 1.8
  • Buildozer 0.27dev
  • Python-For-Android (version downloaded by buildozer)
  • APK Compiled in Ubuntu 14.04 LTS, Linux 3.13.0-46-generic Build with lxml not working #79-Ubuntu SMP x86_64 GNU/Linux (note it works correclty under ubuntu so it's not the ubuntu pygame version)

TRACEBACK

When starting a program and launching pygame.midi.init() on android I get:

I/python  (13347):  Traceback (most recent call last):
I/python  (13347):    File "/myprojectdir/.buildozer/android/app/main.py", line 48, in <module>
I/python  (13347):    File "/myprojectdir/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/app.py", line 766, in run
I/python  (13347):    File "/myprojectdir/.buildozer/android/app/main.py", line 41, in build
I/python  (13347):    File "/myprojectdir/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/pygame/midi.py", line 71, in init
I/python  (13347):  ImportError: No module named pypm
I/python  (13347): Python for android ended.
I/AndroidRuntime(13347): VM exiting with result code 0, cleanup skipped.

Reproducing the problem

midi.kv file:


<Display>:
    orientation:"horizontal"
    TextInput:
        id: text_input
        text: root.display_text
        size_hint: 0.5, 1.

    BoxLayout:
        orientation:"vertical"
        size_hint: 0.5, 1.
        Label:
            text: "N# devices: %d " % root.n_devices

main.py file:


import pygame.midi
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty,  StringProperty

class Display(BoxLayout):
    n_devices = NumericProperty(0)
    display_text = StringProperty("LALA")

class MidiApp(App):

    def build(self):
        display = Display()

        pygame.midi.init()  #This is the line that breaks
        display. n_devices = pygame.midi.get_count()
        display.display_text = str(dir(pygame.midi))
        return display

if __name__ == "__main__":
    MidiApp().run()

GREP

Checking the source code, the results of grepping
$ grep -iR pypm *
Binary file android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.pyo matches
Binary file android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.pyc matches
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py:_pypm = None
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: global _init, _pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: import pygame.pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: _pypm = pygame.pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: _pypm.Initialize()
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: global _init, _pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: _pypm.Terminate()
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: del _pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: #del pygame._pypm
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: return _pypm.CountDevices()
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: return _pypm.GetDefaultInputDeviceID()
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: return _pypm.GetDefaultOutputDeviceID()
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: return _pypm.GetDeviceInfo(an_id)
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: self._input = _pypm.Input(device_id, buffer_size)
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: if r == _pypm.TRUE:
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: elif r == _pypm.FALSE:
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: self._output = _pypm.Output(device_id, latency)
android/platform/python-for-android/dist/miditest/python-install/lib/python2.7/site-packages/pygame/midi.py: return _pypm.Time()
Binary file android/platform/python-for-android/dist/miditest/private/lib/python2.7/site-packages/pygame/midi.pyo matches
Binary file android/platform/python-for-android/.git/objects/pack/pack-5e24aee07aeb8a388e2646faae0bee9d8034838e.pack matches
android/platform/python-for-android/recipes/pygame/Setup:# pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)

@victor-rene
Copy link

pygame / lib / midi.py

pygame / src / pypm.pyx

It seems pygame pypm module is not included in Py4A default build. What you can do is enable it by hand during your setup. Please refer to:
python-for-android/recipes/pygame/Setup

@tito
Copy link
Member

tito commented Mar 28, 2015

More than that, pygame is going to be removed soon on Android (at least deprecated), as we are all moving to SDL2. Pygame on android is half-used, mixed with a custom SDL 1.3 (never released version). It's already cleaned and working on iOS.

Midi has never been a target for Kivy, but i guess you might try to look (or give a recipe) to compile another midi library then :)

@tito tito closed this as completed May 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants