At its current state, GNURadio 3.7 does not work out-of-the-box with Python 3. This is a guide to building GNURadio from source to use a Python 3 Anaconda environment. This setup is particularly nice since you can still easily import other Python packages with conda
and use them inside GNURadio blocks.
This guide assumes you have installed all the system dependencies of GNURadio (not including the Python ones) and Anaconda 3. You can find the list of system dependencies on the GNURadio website. You need all the ones that aren't called gnuradio
or python-*
.
Pull the GNURadio source and the environment.yml
file that describes the conda environment that plays nice with GNURadio. At the time that this tutorial was written, this worked for 72aa97d.
$ git clone --recurse-submodules git@github.com:gnuradio/gnuradio.git
$ cd gnuradio
$ wget https://gist.githubusercontent.com/rytse/dd66e066b4b218022ac111e4a3618660/raw/66aca50cc7a66e0f212301f8e700402a0a6acf7c/gr_py3_env.yml
Create the conda environment (the one described by the yml file is called "dsp") and build GNURadio using the Python interpreter and libraries in the conda environment.
$ conda env create -f gr_py3_env.yml
$ conda activate dsp
$ mkdir build
$ cd build
$ cmake -DPYTHON_EXECUTABLE=~/anaconda3/envs/dsp/bin/python3.7 -DPYTHON_INCLUDE_DIR=~/anaconda3/envs/dsp/include/python3.7m -DPYTHON_LIBRARY=~/anaconda3/envs/dsp/lib/libpython3.7m.so -DCMAKE_INSTALL_PREFIX=~/anaconda3/envs/dsp ../
$ make -j$(nproc)
$ sudo make install
$ sudo ldconfig
By default, make
installs to -DCMAKE_INSTALL_PREFIX/libs/<python version>/dist-packages/
, but the conda Python interpreter looks for packages in <prefix>/libs/<python version>/site-packages/
. Thus, we symlink to the packages installed.
$ ln -s ~/anaconda3/envs/dsp/lib/python3.7/dist-packages/* ~/anaconda3/envs/dsp/lib/python3.7/site-packages
And that's it. You should now be able to import GNURadio from (dsp)
and run grc blocks written in (dsp)
.