0
votes

I have successfully installed gnuradio on my windows machine and try to integrate the python environment that comes with it (Python 2.7) with PyCharm v2018. I create a new project and add a user-defined path for packages to point where all the gnuradio libraries are (C:\Program Files\GNURadio-3.7\lib\site-packages).

Everything seems to work fine in the sense that Pycharm can see all the gnuradio packages without complaining. But when I run the command "from gnuradio import uhd as uhd", or import any other sub-package for that matter, I get an error complaining about not being able to load the corresponding swig file, although it does exist in the expected location.

Traceback (most recent call last): File "C:/Users/ep29413/PycharmProjects/GnuRadio/junk.py", line 3, in from gnuradio import fft as uhd File "C:\junk\site-packages\gnuradio\fft__init__.py", line 32, in from fft_swig import * File "C:\junk\site-packages\gnuradio\fft\fft_swig.py", line 17, in _fft_swig = swig_import_helper() File "C:\junk\site-packages\gnuradio\fft\fft_swig.py", line 16, in swig_import_helper return importlib.import_module('_fft_swig') File "C:\Program Files\GNURadio-3.7\gr-python27\lib\importlib__init__.py", line 37, in import_module import(name) ImportError: No module named _fft_swig

Note that when I run the batch file that initializes the python environment for gnuradio outside PyCharm the above command works just fine.

Any help will be greatly appreciated.

1

1 Answers

0
votes

After some digging, I figured out how to properly set up PyCharm to work with Gnuradio. The issue was that the environment, and in particular all the paths, were not properly initialized. I got a hint from the batch file called "run_gr.bat" that comes with gnuradio and setups the gnuradio python interpreter.

The following environment variables have to be set prior to executing any gnuradio python script:

PYTHONHOME=C:\Program Files\GNURadio-3.7\gr-python27 
PYTHONPATH=C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages;C:\Program Files\GNURadio-3.7\gr-python27\dlls;C:\Program Files\GNURadio-3.7\gr-python27\libs;C:\Program Files\GNURadio-3.7\gr-python27\lib;C:\Program Files\GNURadio-3.7\lib\site-packages;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\pkgconfig;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\gtk-2.0\glib;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\gtk-2.0;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\wx-3.0-msw;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\sphinx;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\lxml-3.4.4-py2.7-win.amd64.egg;C:\Program Files\GNURadio-3.7\gr-python27\Lib\site-packages\gnuradio\analog 
PATH=C:\Program Files\GNURadio-3.7\bin;C:\Program Files\GNURadio-3.7\gr-python27\dlls;C:\Program Files\GNURadio-3.7\gr-python27;
%PATH% GRC_BLOCKS_PATH=C:\Program Files\GNURadio-3.7\share\gnuradio\grc\blocks 
UHD_PKG_DATA_PATH=C:\Program Files\GNURadio-3.7\share\uhd;C:\Program Files\GNURadio-3.7\share\uhd\images 
UHD_IMAGES_DIR=C:\Program Files\GNURadio-3.7\share\uhd\images 
UHD_RFNOC_DIR=C:\Program Files\GNURadio-3.7\share\uhd\rfnoc

The environment variables need to be added in two places:

  1. File -> Settings -> Build, Execution, Deployment -> Console -> Python Console

    Add all above paths under "Environment Variables"

    This allows the console to properly run gnuradio scripts when cutting and pasting

  2. Run -> Edit Configurations -> Templates -> Python

    Again add all above paths under "Environment Variables"

    This allows the run/debug sessions to properly run gnuradio scripts

Hope that helps