Skip to content

fix: Error: python3 -c "import soundcard" #191#192

Open
AlexanderShad wants to merge 1 commit into
bastibe:masterfrom
AlexanderShad:master
Open

fix: Error: python3 -c "import soundcard" #191#192
AlexanderShad wants to merge 1 commit into
bastibe:masterfrom
AlexanderShad:master

Conversation

@AlexanderShad

Copy link
Copy Markdown

No description provided.

@cclauss

cclauss commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What operating system and Python version are you trying to fix?
% uvx --with=soundcard python3 -c "import soundcard"

Works fine on macOS 26 using Python 3.14.

@AlexanderShad

Copy link
Copy Markdown
Author

What operating system and Python version are you trying to fix? % uvx --with=soundcard python3 -c "import soundcard"

Works fine on macOS 26 using Python 3.14.

Hello

python - 3.13.13

I removed the patch, built the RPM package without it, and tested it. The result is below.

~ ❯ python3 -c "import soundcard"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import soundcard
  File "/usr/lib/python3/site-packages/soundcard/__init__.py", line 4, in <module>
    from soundcard.pulseaudio import *
  File "/usr/lib/python3/site-packages/soundcard/pulseaudio.py", line 290, in <module>
    _pulse = _PulseAudio()
  File "/usr/lib/python3/site-packages/soundcard/pulseaudio.py", line 95, in __init__
    self.context = _pa.pa_context_new(self.mainloop_api, self._infer_program_name().encode())
                                                         ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/site-packages/soundcard/pulseaudio.py", line 114, in _infer_program_name
    return sys.argv[1][:30] + "..."
           ~~~~~~~~^^^
IndexError: list index out of range

~ ❯ rpm -qa | grep soundcard
python3-module-soundcard-0.4.6-alt2.noarch

@cclauss

cclauss commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

@AlexanderShad

Copy link
Copy Markdown
Author

What operating system?
% unane -a

OS: ALT Regular x86_64

On Ubuntu, I needed to do: https://github.com/bastibe/SoundCard/pull/200/files#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fR16-R23

Thanks, but in my case this does not solve the problem mentioned above.

Perhaps when the maintainer python3 at ALT updates Python to version 3.14 the problem will be solved, but for now it exists.

@cclauss

cclauss commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What does this print?
% pulseaudio --version && pulseaudio --start

I doubt that upgrading Py3.13 to Py3.14 will fix anything.

@bastibe

bastibe commented Jun 13, 2026

Copy link
Copy Markdown
Owner

You seem to be running into a bug in _infer_program_name. The method could probably use a try/catch to safeguard against unusual command lines. I'd be happy to accept a pull request if you investigate the issue.

@AlexanderShad

Copy link
Copy Markdown
Author

What does this print? % pulseaudio --version && pulseaudio --start

❯ pulseaudio --version && pulseaudio --start
pulseaudio 17.0

I didn't have Pulseaudio installed.

I installed it and launched it, but it didn't solve the problem.

@cclauss

cclauss commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Cool! Now add:
% pacmd load-module module-null-sink channels=6 rate=48000 && pactl info

@AlexanderShad

Copy link
Copy Markdown
Author
return sys.argv[1][:30] + "..."

Personally, I worked around the error like this:

return sys.argv[0][:30] + "..."

I don't understand where the value of sys.argv[1] should come from if it's not there.

sys.argv[0] = -c

len(sys.argv) = 1

print(*sys.argv) = -c

Where does sys.argv[1] come from?

Or am I missing something?

@AlexanderShad

Copy link
Copy Markdown
Author

pacmd load-module module-null-sink channels=6 rate=48000 && pactl info

❯ pacmd load-module module-null-sink channels=6 rate=48000 && pactl info
Server line: /run/user/1000/pulse/native
Library protocol version: 35
Server protocol version: 35
Runs locally: yes
Client number: 544
Memory block size: 65472
Username: shad
Hostname: machenike
Server name: PulseAudio (on PipeWire 1.6.6)
Server version: 15.0.0
Default sample specification: float32le 2-channel
Default channel layout: front-left, front-right
Default audio sink: alsa_output.pci-0000_01_00.1.hdmi-stereo
Default source: alsa_input.pci-0000_00_1f.3.analog-stereo
Cookie: 5dfc:53fe

@cclauss

cclauss commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Awesome! Now do:
% python3 -c "import soundcard"

@AlexanderShad

Copy link
Copy Markdown
Author

Awesome! Now do: % python3 -c "import soundcard"

Снимок экрана от 2026-06-13 22-29-36 Снимок экрана от 2026-06-13 22-29-47

@cclauss

cclauss commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

This works on Ubuntu without modifying _infer_program_name():

sudo apt update && sudo apt install --yes pulseaudio  # or the equivelent on your Linux
pulseaudio --version  # optional but a good sanity check
pulseaudio --start
pacmd load-module module-null-sink channels=6 rate=48000
pactl info  # optional but a good sanity check
python3 -c "import soundcard"

@AlexanderShad

Copy link
Copy Markdown
Author

To be honest, I don’t even know what to answer you.

@AlexanderShad

Copy link
Copy Markdown
Author

The module itself works fine.

I haven't had any problems with it other than this one.

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

Successfully merging this pull request may close these issues.

3 participants