vishnubob / python-midi

Python MIDI library
MIT License
1.51k stars 370 forks source link

AttributeError: 'module' object has no attribute 'SND_SEQ_OPEN_DUPLEX' #129

Open mgedmin opened 7 years ago

mgedmin commented 7 years ago

I'm trying to run the tests for this package, and I keep getting

======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'SND_SEQ_OPEN_DUPLEX')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/src/python-midi/env/local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/mg/src/python-midi/env/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/mg/src/python-midi/env/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/mg/src/python-midi/tests/tests.py", line 8, in <module>
    import midi.sequencer as sequencer
  File "/home/mg/src/python-midi/env/local/lib/python2.7/site-packages/midi/sequencer/__init__.py", line 2, in <module>
    from sequencer import *
  File "/home/mg/src/python-midi/env/local/lib/python2.7/site-packages/midi/sequencer/sequencer.py", line 2, in <module>
    import sequencer_alsa as S
  File "/home/mg/src/python-midi/src/sequencer_alsa/__init__.py", line 2, in <module>
    from sequencer import *
  File "/home/mg/src/python-midi/src/sequencer_alsa/sequencer.py", line 22, in <module>
    class Sequencer(object):
  File "/home/mg/src/python-midi/src/sequencer_alsa/sequencer.py", line 26, in Sequencer
    'alsa_sequencer_stream':S.SND_SEQ_OPEN_DUPLEX,
AttributeError: 'module' object has no attribute 'SND_SEQ_OPEN_DUPLEX'

Steps to reproduce:

  1. sudo apt-get install build-essential python-dev swig libasound2-dev
  2. git clone https://github.com/vishnubob/python-midi
  3. cd python-midi
  4. virtualenv env
  5. env/bin/pip install .
  6. env/bin/pip install nose
  7. env/bin/nosetests
mgedmin commented 7 years ago

I think I know what's happening here: somehow ./src shows up on my sys.path, which means Python thinks sequencer_alsa is the package, and not the sequencer_alsa.py module inside it.

I think if you used an explicit relative import (from . import sequencer_alsa as S) as I did in https://github.com/vishnubob/python-midi/pull/130/commits/2f7f9db45ca1a120ed6b5ab4d64d24815089b9a6, this problem would go away.