mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

'pa_runtime_path' function not found #44

Closed bark11 closed 4 years ago

bark11 commented 4 years ago

When importing pulsectl on Windows 10 I get an AttributeError. Here's the traceback:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    import multimuter as mm
  File "D:\python\MultiMuter\multimuter.py", line 1, in <module>
    import pulsectl
  File "C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pulsectl\__init__.py", line 4, in <module>
    from . import _pulsectl
  File "C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pulsectl\_pulsectl.py", line 676, in <module>
    pa = LibPulse()
  File "C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pulsectl\_pulsectl.py", line 632, in __init__
    func, args, res_proc = getattr(p, k), None, None
  File "C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 386, in __getattr__
    func = self.__getitem__(name)
  File "C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 391, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'pa_runtime_path' not found
mk-fg commented 4 years ago

Hi,

Not sure if that particular function makes sense on windows, which is why maybe it's missing there.

Can you grab _pulsectl.py file from this link - http://ix.io/2o0F - and replace the one you have (C:\Users\barte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pulsectl\_pulsectl.py) with it, then re-run same thing, pasting/linking its output here?

It has following change:

diff --git a/pulsectl/_pulsectl.py b/pulsectl/_pulsectl.py
index 4422ddf..24b9bd9 100644
--- a/pulsectl/_pulsectl.py
+++ b/pulsectl/_pulsectl.py
@@ -629,7 +629,10 @@ class LibPulse(object):

     self.funcs = dict()
     for k, spec in self.func_defs.items():
-      func, args, res_proc = getattr(p, k), None, None
+      try: func, args, res_proc = getattr(p, k), None, None
+      except AttributeError:
+        print(f'----- missing func: {k}')
+        continue
       if spec:
         if not isinstance(spec, tuple): spec = (spec,)
         for v in spec:

And should print ----- missing func: pa_runtime_path at least, as well as what else might be missing there. If it's not much and enough for more-or-less working module, can probably just skip missing ones like in patch above, limiting some of module's functionality, but oh well.

Never tested the module on windows myself, didn't think it even had recent-enough pulseaudio working there natively (without WSL and such), but guess maybe it changed or can change. What pulseaudio version do you have there? (if you have pulseaudio binary can probably check by running pulseaudio --version)

bartekmuzyk commented 4 years ago

PulseAudio isn't natively built-in to Windows, but the binaries can be downloaded from the freedesktop site in their Windows support section. I have PulseAudio version 1.1. I changed the code as you told me and this kinda fixed the problem. Now I don't get the AttributeError and instead get the '----- missing func: pa_runtime_path' message printed out which should've happened. But now I get an error saying Failed to connect to PulseAudio server. I don't think that this is caused by the library, but instead by the daemon. I checked and it seems that the daemon is not able to start, as the pulseaudio --start command just says E: [(null)] pulsecore/lock-autospawn.c: Assertion '(*_errno()) == 11' failed at pulsecore/lock-autospawn.c:205, function empty_pipe(). Aborting.. If anybody understands this error I would be grateful if you could tell me.

mk-fg commented 4 years ago

binaries can be downloaded from the freedesktop site in their Windows support section. I have PulseAudio version 1.1.

Oh wow, it's from 2011 - a 9 year old release!

I'm surprised you only get that one "missing func" message and not like 30 of them, but guess most of the functionality was already there in that old 1.1 release.

Don't know how to fix daemon crashing on start of course, but not entirely sure if it's supposed to work on Windows 10, or even Windows 8 or 7 for that matter, as I think that release dates back to Windows XP days.

If you really need PulseAudio on Windows (which probably has its own sound systems, more native than pulse), then I'd suggest trying to run it under WSL (Windows Subsystem for Linux) - afaik especially with WSL2 it's supposed to support media apps (incl. graphics APIs like DirectX/OpenGL/Vulkan), so should probably work. And WSL should not need any kind of special ancient pulseaudio build, you should be able to just apt-get install pulseaudio, if it doesn't already come pre-installed there (as it tends to be on Ubuntu).

Guess I'll close this issue, as don't think I can do anything about last problem above, but if you get pulseaudio server to run and this module to work with it in some capacity - do leave a comment, can probably add check for windows build that'd skip that pa_runtime_path lookup. As it is though, despite all other API bits apparently being present, still not sure it'd work with such an old release on windows, though see no clear reason why it wouldn't either.

bartekmuzyk commented 4 years ago

Wow, I didn't know that version 1.1 was that old! Thanks for helping me, I'll search for native libraries.