Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'pa_sink #10

Open
zhainhart opened this issue Jun 8, 2019 · 8 comments
Open

AttributeError: 'module' object has no attribute 'pa_sink #10

zhainhart opened this issue Jun 8, 2019 · 8 comments

Comments

@zhainhart
Copy link

after installing this module, this error occurred when executing the flow graph

top_block.py", line 99, in init
self.pulseaudio_pa_sink_0 = gr_pulseaudio.pa_sink(
AttributeError: 'module' object has no attribute 'pa_sink

@WGH-
Copy link
Collaborator

WGH- commented Jun 19, 2019

I'll check it.

@WGH-
Copy link
Collaborator

WGH- commented Jun 24, 2019

Could you please tell me more about your environment and how you installed the package? I have no idea why it might have happened.

@dsoprea
Copy link

dsoprea commented Sep 29, 2020

There's a few issues. I am encountering this on Raspian 10.

First, the library is being installed as /usr/local/lib/libgnuradio-pulseaudio.so:

-- Installing: /usr/local/include/gr-pulseaudio/pa_source.h
-- Installing: /usr/local/lib/libgnuradio-pulseaudio.so
-- Installing: /usr/local/lib/python2.7/dist-packages/gr_pulseaudio/_pulseaudio_swig.so

...but, it's not being permissioned correctly:

$ ls -l /usr/local/lib
...
-rw-r--r-- 1 root root  90188 Sep 29 04:15 libgnuradio-pulseaudio.so
...

You need to run chmod u+x,g+x,o+x on it.

But, this isn't enough. The swig binary still couldn't resolve it:

>>> import gr_pulseaudio._pulseaudio_swig
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libgnuradio-pulseaudio.so: cannot open shared object file: No such file or directory

More to the point, ctypes doesn't seem to be respecting the system library resolution path:

$ cat /etc/ld.so.conf.d/libc.conf 
# libc default configuration
/usr/local/lib
>>> import ctypes
>>> libc = ctypes.CDLL("libgnuradio-pulseaudio.so")  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libgnuradio-pulseaudio.so: cannot open shared object file: No such file or directory

So, I tried exporting LD_LIBRARY_PATH:

$ LD_LIBRARY_PATH=/usr/local/lib python
Python 2.7.16 (default, Oct 10 2019, 22:02:15) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gr_pulseaudio
>>> dir(gr_pulseaudio)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_pulseaudio_swig', 'high_res_timer_epoch', 'high_res_timer_now', 'high_res_timer_now_perfmon', 'high_res_timer_tps', 'pa_sink', 'pa_sink_make', 'pa_sink_sptr', 'pa_sink_sptr_swigregister', 'pa_sink_swigregister', 'pa_source', 'pa_source_make', 'pa_source_sptr', 'pa_source_sptr_swigregister', 'pa_source_swigregister', 'pulseaudio_swig']

That fixed the import. I'd recommend adding that to your user-profile script. Make sure to log out and log back in if you're in X.

Finally, this obscured all of the issues (in init.py):

try:
	# this might fail if the module is python-only
	from pulseaudio_swig import *
except ImportError:
	pass

I'm not sure why you're unconditionally suppressing all import issues. Once I removed the guards, I started seeing:

$ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gr_pulseaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/gr_pulseaudio/__init__.py", line 29, in <module>
    from pulseaudio_swig import *
  File "/usr/local/lib/python2.7/dist-packages/gr_pulseaudio/pulseaudio_swig.py", line 17, in <module>
    _pulseaudio_swig = swig_import_helper()
  File "/usr/local/lib/python2.7/dist-packages/gr_pulseaudio/pulseaudio_swig.py", line 16, in swig_import_helper
    return importlib.import_module('_pulseaudio_swig')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _pulseaudio_swig

I'd also recommend that you get rid of this flow (in pulseaudio_swig.py):

        mname = '.'.join((pkg, '_pulseaudio_swig')).lstrip('.')
        try:
            return importlib.import_module(mname)
        except ImportError:
            return importlib.import_module('_pulseaudio_swig')

There are three variations of this. The first import should never fail under normal circumstances. If you have something configured incorrectly on your system, it will just fail over to the second import, which is likely to fail (unless you're running from inside that package path) and then print a message that cites an unhelpful error message rather than the proper error message.

@dsoprea
Copy link

dsoprea commented Sep 29, 2020

Note that I needed to set LD_LIBRARY_PATH from the command-line and then call GNU Radio Companion directly in order for it to have an effect.

@WGH-
Copy link
Collaborator

WGH- commented Oct 22, 2020

You're right that there's lots of ugly code in there, but interestingly I couldn't reproduce the problem in clean Debian 10 container. import gr_pulseaudio simply worked.

I'll try to clean up what you suggested anyway.

@WGH-
Copy link
Collaborator

WGH- commented Oct 22, 2020

Besides, since my distro (Gentoo) already moved on, and removed Python 2 support from lots of packages, including GNU Radio, I'll need to add Python 3 support anyway, and it would be hard without cleaning up first.

@WGH-
Copy link
Collaborator

WGH- commented Oct 22, 2020

First, the library is being installed as /usr/local/lib/libgnuradio-pulseaudio.so:
...but, it's not being permissioned correctly:

@dsoprea

Are you sure libraries must have executable bit set, though? I checked various Linux systems I have access to, including Rasbpian Stretch, and vast majority of libraries on every system was non-executable.

Compare find /usr/lib/ /lib/ '!' -executable -type f -name '*.so' and find /usr/lib/ /lib/ -executable -type f -name '*.so'

https://www.debian.org/doc/debian-policy/ch-sharedlibs.html

Shared libraries should not be installed executable, since the dynamic linker does not require this and trying to execute a shared library usually results in a core dump.

@WGH-
Copy link
Collaborator

WGH- commented Oct 22, 2020

Oh, well, apparently, most of the crap simply comes from default gr_modtool project template.

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

No branches or pull requests

3 participants