1

I would like to make calls from python to blocks in gnuradio 3.8 from PyCharm CE 2019.2 on Ubuntu 18.04. The project interpreter set in Pycharm is the virtual environment created when the pycharm project was created. I have seen suggestions (How do I import modules in pycharm?) to add a line like:

/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages

to the interpreter path (under File->Settings->Project:my_proj->Project Interpreter->Gear Symbol->Show All->Show Paths for Selected Interpreter).

From the python console, this results in the following error when I attempt to import gnuradio blocks:

PyDev console: starting.
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
import gnuradio
from gnuradio import blocks
Traceback (most recent call last):
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libgnuradio-blocks.so.3.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/__init__.py", line 32, in <module>
    from .blocks_swig import *
  File "/snap/pycharm-community/167/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig.py", line 24, in <module>
    from .blocks_swig0 import *
  File "/snap/pycharm-community/167/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 17, in <module>
    _blocks_swig0 = swig_import_helper()
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 16, in swig_import_helper
    return importlib.import_module('_blocks_swig0')
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_blocks_swig0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libgnuradio-blocks.so.3.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/snap/pycharm-community/167/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/__init__.py", line 36, in <module>
    from .blocks_swig import *
  File "/snap/pycharm-community/167/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig.py", line 24, in <module>
    from .blocks_swig0 import *
  File "/snap/pycharm-community/167/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 17, in <module>
    _blocks_swig0 = swig_import_helper()
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/gnuradio/blocks/blocks_swig0.py", line 16, in swig_import_helper
    return importlib.import_module('_blocks_swig0')
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_blocks_swig0'

I believe that I have libgnuradio installed:

~/devel/gnuradio3_8/lib$ ls
cmake                            libgnuradio-qtgui.so.3.8.0
libgnuradio-analog.so            libgnuradio-qtgui.so.3.8.0.0
libgnuradio-analog.so.3.8.0      libgnuradio-runtime.so
libgnuradio-analog.so.3.8.0.0    libgnuradio-runtime.so.3.8.0
libgnuradio-audio.so             libgnuradio-runtime.so.3.8.0.0
libgnuradio-audio.so.3.8.0       libgnuradio-trellis.so
libgnuradio-audio.so.3.8.0.0     libgnuradio-trellis.so.3.8.0
libgnuradio-blocks.so            libgnuradio-trellis.so.3.8.0.0
libgnuradio-blocks.so.3.8.0      libgnuradio-uhd.so
libgnuradio-blocks.so.3.8.0.0    libgnuradio-uhd.so.3.8.0
libgnuradio-channels.so          libgnuradio-uhd.so.3.8.0.0
libgnuradio-channels.so.3.8.0    libgnuradio-utilities.so
libgnuradio-channels.so.3.8.0.0  libgnuradio-utilities.so.1.0.0git
libgnuradio-digital.so           libgnuradio-utilities.so.v1.0-compat-xxx-xunknown
libgnuradio-digital.so.3.8.0     libgnuradio-vocoder.so
libgnuradio-digital.so.3.8.0.0   libgnuradio-vocoder.so.3.8.0
libgnuradio-dtv.so               libgnuradio-vocoder.so.3.8.0.0
libgnuradio-dtv.so.3.8.0         libgnuradio-wavelet.so
libgnuradio-dtv.so.3.8.0.0       libgnuradio-wavelet.so.3.8.0
libgnuradio-fec.so               libgnuradio-wavelet.so.3.8.0.0
libgnuradio-fec.so.3.8.0         libgnuradio-zeromq.so
libgnuradio-fec.so.3.8.0.0       libgnuradio-zeromq.so.3.8.0
libgnuradio-fft.so               libgnuradio-zeromq.so.3.8.0.0
libgnuradio-fft.so.3.8.0         libuhd.so
libgnuradio-fft.so.3.8.0.0       libuhd.so.3.14.1
libgnuradio-filter.so            libvolk.so
libgnuradio-filter.so.3.8.0      libvolk.so.2.0
libgnuradio-filter.so.3.8.0.0    pkgconfig
libgnuradio-pmt.so               python2.7
libgnuradio-pmt.so.3.8.0         python3
libgnuradio-pmt.so.3.8.0.0       python3.6
libgnuradio-qtgui.so             uhd

What is the right way to import gnuradio?

rhz
  • 960
  • 14
  • 29
  • I think you are just missing the actual libgnuradio ... `apt-get install libgnuradio` ... thats what it looks like to me at least – Joran Beasley Nov 27 '19 at 21:54
  • @JoranBeasley, I think I do have libgnuradio installed (see listing added to original question). – rhz Nov 27 '19 at 22:07
  • its not usually installed there i htink ... its usually installed in like /var/lib or something ... it looks like you might have downloaded that and extracted it? instead of apt-get install? maybe? also it might need to be `apt-get install libgnuradio-dev` or `apt-get install libgnuradio-devel` ... maybe – Joran Beasley Nov 27 '19 at 22:11
  • Yes. I have gnuradio3.7 in the usual place and 3.8 is here under my home directory. – rhz Nov 27 '19 at 23:01
  • I should probably uninstall 3.7 and re-install 3.8 in the usual locaiton. – rhz Nov 28 '19 at 00:00

1 Answers1

0

ImportError: libgnuradio-blocks.so.3.8.0: cannot open shared object file: No such file or directory

Yes. I have gnuradio3.7 in the usual place and 3.8 is here under my home directory

You need to add the path were you've installed gnuradio libs (~/devel/gnuradio3_8/lib) to the LD_LIBRARY_PATH environment variable.

I'm not familiar with pycharm but from your terminal you could execute

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/devel/gnuradio3_8/lib

and then start pycharm from the same terminal or add the same to your ~/.bash_profile

In case you've installed gnuradio using pybombs there will be A setup_env.sh script in ~/devel/gnuradio3_8 that you could source from the terminal

$ source setup_env.sh
Community
  • 1
  • 1
Vasil Velichkov
  • 1,236
  • 11
  • 17
  • Pybombs was used. The setup_env.sh has a line: export LD_LIBRARY_PATH="/home/my_name/devel/gnuradio3_8/lib:/home/my_name/devel/gnuradio3_8/lib64/:$LD_LIBRARY_PATH" When I run this script and call pycharm from the command line it works. LD_LIBRARY_PATH also appears in pycharm's list of env variables. When I attempt to define LD_LIBRARY_PATH as a user defined env variable in pycharm, I get the original error. I wonder if there are additional env variables I need to define w/in pycharm. – rhz Dec 02 '19 at 19:58
  • What is the value of LD_LIBRARY_PATH in the pycharm's list ov env variables? All variables that you need to define are listed in the setup_env.sh and the two most important ones are `PYTHONPATH` and `LD_LIBRARY_PATH`. The fact that it works when you manually source setup_env.sh and start pycharm from the terminal proves that those are the only variables that you need. You could also try adding those variables (or source setup_env.sh) in your ~/.bash_profile and then logout/login. – Vasil Velichkov Dec 03 '19 at 00:41
  • See also https://stackoverflow.com/a/40323147/2315085 and https://stackoverflow.com/a/38048618/2315085 – Vasil Velichkov Dec 03 '19 at 00:50
  • All the environment variables in setup_env.sh appear in pycharm's list of system env variables: GRC_BLOCKS_PATH, LD_LIBRARY_PATH, LIBRARY_PATH, PATH, PKG_CONFIG_PATH, PYBOMBS_PREFIX, PYTHON_PATH. In answer to your question, the value of LD_LIBRARY_PATH as read from pycharm's list of system env variables is: /home/my_name/devel/gnuradio3_8/lib:/home/my_name/devel/gnuradio3_8/lib64/: – rhz Dec 04 '19 at 02:09
  • How do you set the env variables in pycharm? Try following this https://www.techcoil.com/blog/how-to-set-environment-variables-for-your-python-application-from-pycharm/. And then try to validate you have set them correctly with a simple python script that only prints the value `import os; print(os.environ.get('LD_LIBRARY_PATH'));` – Vasil Velichkov Dec 04 '19 at 18:58