21

When I was trying to play a wave file with PyAudio-0.2.11 in a python-3.10.1 virtualenv(created with python-3.9.0 venv and upgraded), I received an exception and nothing is played, others just go well.

Exception in thread WavPlayer:rsrc/sound.wav:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/Code/py/tetris/tetris.py", line 39, in run
    self.play()
  File "/Code/py/tetris/tetris.py", line 35, in play
    self.stream.write(data)
  File "/Code/py/tetris/.venv/lib/python3.10/site-packages/pyaudio.py", line 584, in write
    pa.write_stream(self._stream, frames, num_frames,
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I do not know what '#' format stands for, and I am sure that my code has nothing to do with C API, but it run well under python-3.9.x, is that a problem with the PyAudio library itself? How can I solve that?

CristiFati
  • 38,250
  • 9
  • 50
  • 87
gynamics
  • 311
  • 1
  • 2
  • 4

3 Answers3

19

Unfortunately, a breaking change was introduced in Python 3.10 (see bpo-40943 and PEP-0353), and thus PyAudio needs updated.

EDIT: This has been fixed upstream since PyAudio 0.2.12! Leaving the interim below for posterity, but a simple version bump is all that is needed now.


I've submitted a fix upstream, but as the project has not been updated since 2017, I'm not quite sure how quick it will get reviewed.

In the meantime, you are free to build my fork from source and use that :)

skeh
  • 191
  • 3
3

Necroposting.

As @skeh indicated, starting with Python 3.10 some (backward compatible) functionality was disabled on purpose. That means that some extension modules will no longer work OOTB.
Check [GitHub]: python/cpython - PEP 353: Drop support for PyArg_ParseTuple() "#" formats when PY_SSIZE_T_CLEAN is not defined for more details.

PyAudio (v0.2.11) is one such module.
Things are fixed in v0.2.12 (which was released in the meantime).

Python 3.11 .whls were not published on [PyPI]: PyAudio 0.2.12 - Download files at answer time (they were added afterwards).
I built and placed them at [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyAudio/v0.2.12.

Also forked the (original) PyAudio repo at: [GitHub]: CristiFati/pyaudio - PyAudio

Similar problem on another package: [SO]: Can't install pyo using pip (@CristiFati's answer).

CristiFati
  • 38,250
  • 9
  • 50
  • 87
1

I've had this error as well. Tried installing a variety of pymongo versions until resolved. version 3.12 did it for me

pip install --upgrade pymongo=3.12

Eran Moshe
  • 3,062
  • 2
  • 22
  • 41