TeamPyOgg / PyOgg

Simple OGG Vorbis, Opus and FLAC bindings for Python
The Unlicense
63 stars 27 forks source link

AttributeError: module 'pyogg.opus' has no attribute 'opus_int32' #82

Closed paddatrapper closed 3 years ago

paddatrapper commented 3 years ago

I'm unable to import OpusEncoder using the current master (3783343):

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/kyle/projects/bitcast/mumbleice/mumbleice/__main__.py", line 44, in <module>
    icecast = IcecastConnector(cfg['server'], cfg.getint('port'),
  File "/home/kyle/projects/bitcast/mumbleice/mumbleice/bot.py", line 78, in __init__
    self.encoder = OpusEncoder()
  File "/home/kyle/projects/bitcast/mumbleice/pyenv/lib/python3.9/site-packages/pyogg/opus_encoder.py", line 20, in __init__
    self.set_max_bytes_per_frame(4000)
  File "/home/kyle/projects/bitcast/mumbleice/pyenv/lib/python3.9/site-packages/pyogg/opus_encoder.py", line 128, in set_max_bytes_per_frame
    self._max_bytes_per_frame = opus.opus_int32(max_bytes)
AttributeError: module 'pyogg.opus' has no attribute 'opus_int32'
mattgwwalker commented 3 years ago

Thanks for your feedback.

Could you please provide a bit more information about the code that generates the error? A minimal example would be ideal.

Also, have you looked at the example 03-write-ogg-opus.py? That shows usage of OpusBufferedEncoder which (internally) uses OpusEncoder.

Cheers,

Matthew

paddatrapper commented 3 years ago

A minimal example:

$ python3
Python 3.9.1+ (default, Jan 10 2021, 15:42:50) 
[GCC 10.2.1 20201224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyogg import OpusEncoder
>>> encoder = OpusEncoder()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kyle/projects/bitcast/mumbleice/pyenv/lib/python3.9/site-packages/pyogg/opus_encoder.py", line 20, in __init__
    self.set_max_bytes_per_frame(4000)
  File "/home/kyle/projects/bitcast/mumbleice/pyenv/lib/python3.9/site-packages/pyogg/opus_encoder.py", line 128, in set_max_bytes_per_frame
    self._max_bytes_per_frame = opus.opus_int32(max_bytes)
AttributeError: module 'pyogg.opus' has no attribute 'opus_int32'
>>>
mattgwwalker commented 3 years ago

Thanks for that. I’ll have a look on Monday and get back to you.

Matthew

paddatrapper commented 3 years ago

Found the error - I was missing libopusfile0. There should probably be better error handling here to report missing external libraries if the features that require them are used

mattgwwalker commented 3 years ago

Thanks for reporting back on the cause of the error.

I have committed changes to master that improve the exception messages when OpusFile is missing. Would you like to confirm that they work as expected for you?

Also, your minimal example should now no longer error at all, given that it shouldn't have depended on OpusFile in the first place. Again, would you be so kind as to double-check these changes for me?

Cheers,

Matthew

paddatrapper commented 3 years ago

Yup, that works. Thanks!