pyadi-iio operation in GNURadio 3.8


I'm running pyadi-iio and it all works great in Python 3.7.3.  Thanks!  But I'm having trouble using it with GNURadio3.8.1.0 (which is also running Python 3.7.3). 

Here's my Python 3.7.3 output (not in GNUradio

But if I try the "import adi" in a GNUradio "Python Block", then I get this error "Can't interpret source code: module 'iio' has no attribute 'Device'.  It runs if I comment out the "import adi".  Below is my Python Block code (it's all the standard template except for the import iio and import adi):

Embedded Python Blocks:

Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!

import numpy as np
from gnuradio import gr

import sys

import iio
import adi

class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block
    """Embedded Python Block example - a simple multiply const"""

    def __init__(self, example_param=1.0):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
            name='Embedded Python Block',   # will show up in GRC
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
        self.example_param = example_param

    def work(self, input_items, output_items):
        """example: multiply with constant"""
        output_items[0][:] = input_items[0] * self.example_param
        return len(output_items[0])

  • +1
    •  Analog Employees 
    on Aug 12, 2020 9:33 PM

    Yeah, this is a known problem since gr-iio (3.8) and libiio share the same python module name (iio). This won't be a problem once gr-iio is merged upstream but right now its a problem area for out of tree modules.

    The easiest thing to do is to rename the file to something else then change the imports in pyadi to use that name. For example, if you change to, then you would have to change every "import iio" to import" in pyadi. This should be only 3 files IIR.


  • Travis / John

    I've been following this thread with interest as I've been falling down the same rabbit-hole. Wondering if you can help me take the next steps?

    Objective is Pluto + GNU Radio + Python and pyadi-iio - and nearly there.

    Installation is Linux Mint 20.1 (latest LTS) plus successfully installed GRC v3.8.1, plus the iio libraries built from source, plus now pyadi-iio installed. 

    Copied the idea of renaming '' and changing the import references to the new name in the ADI folder for and

    So, I can now run GRC, complete with Pluto blocks - Yeah!

    I can successfully import my 'newname_iio' in python3

    I can successfully import adi in python 3 - but I am getting an error in running the test script in the PySDR book (Chapter 5).

    test python code is:-

    import adi
    sdr = adi.Pluto('ip:') # or whatever your Pluto's IP is
    sdr.sample_rate = int(2.5e6)

    Response is:

    bob@samsung-i5:~/Documents/Python scripts/Pluto$ python3
    Traceback (most recent call last):
    File "", line 4, in <module>
    File "/usr/local/lib/python3.8/dist-packages/adi/", line 252, in rx
    return self.__rx_complex()
    File "/usr/local/lib/python3.8/dist-packages/adi/", line 173, in __rx_complex
    File "/usr/local/lib/python3.8/dist-packages/adi/", line 129, in _rx_init_channels
    self.__rxbuf = iio.Buffer(self._rxadc, self.__rx_buffer_size, False)
    File "/usr/local/lib/python3.8/dist-packages/", line 1016, in __init__
    self._ctx = device.ctx()
    TypeError: 'Context' object is not callable

    Typing this command   iio_info -s             produces

    bob@samsung-i5:~$ iio_info -s
    Library version: 0.21 (git tag: 359305c)
    Compiled with backends: local xml ip usb
    Unable to create Local IIO context : No such file or directory (2)
    Available contexts:
    0: 0456:b673 (Analog Devices Inc. PlutoSDR (ADALM-PLUTO)), serial=1044739659930001170019003d352948b6 [usb:1.4.5]

    Typing this command:- iio_attr -a -C      produces

    Using auto-detected IIO context at URI "usb:1.4.5"
    IIO context with 15 attributes:
    hw_model: Analog Devices PlutoSDR Rev.B (Z7010-AD9364)
    hw_model_variant: 0
    hw_serial: 1044739659930001170019003d352948b6
    fw_version: v0.32
    ad9361-phy,xo_correction: 39999868
    ad9361-phy,model: ad9364
    local,kernel: 4.19.0-119999-g6edc6cd
    uri: usb:1.4.5
    usb,idVendor: 0456
    usb,idProduct: b673
    usb,release: 2.0
    usb,vendor: Analog Devices Inc.
    usb,product: PlutoSDR (ADALM-PLUTO)
    usb,serial: 1044739659930001170019003d352948b6

    Changing the adi.Pluto call from an ip context to a usb one makes no difference to the error.

    Any ideas on what needs tweaking?  I feel I am so close....

  • 0
    •  Analog Employees 
    on Feb 3, 2021 5:47 PM in reply to Wireless

    What context are you using in gnuradio?


  • 'ip:pluto.local'

    This was tried in the python script as well as the IP address and the usb number.

Reply Children
  • 0
    •  Analog Employees 
    on Feb 3, 2021 6:54 PM in reply to Wireless

    Just for reference, if a USB context is used it cannot have multiple remote contexts using it. So you must be using all IP contexts or just a single USB context from a single application.

    Also, having multiple applications compete over RX or TX buffer control is not a good idea and will likely break. So if you are using sdr.rx(), do not use a source block in GR. The same goes for TX.


  • Travis. I don't intend operating gnuradio and python scripts at the same time. Sorry for the confusion.

    1. Sticking to python with pyadi, why is this simple script throwing an error? 
  • 0
    •  Analog Employees 
    on Feb 3, 2021 7:28 PM in reply to Wireless

    Can you run this code and provide the output:

    import adi

    sdr = adi.Pluto('ip:pluto.local')





  • Can do:-

    ['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_attrs', '_context', '_description', '_devices', '_name', '_version', '_xml', 'attrs', 'clone', 'description', 'devices', 'find_device', 'name', 'set_timeout', 'version', 'xml']
    ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_attrs', '_buffer_attrs', '_channels', '_context', '_debug_attrs', '_device', '_get_trigger', '_id', '_name', '_set_trigger', 'attrs', 'buffer_attrs', 'channels', 'context', 'ctx', 'debug_attrs', 'find_channel', 'id', 'name', 'reg_read', 'reg_write', 'sample_size', 'set_kernel_buffers_count', 'trigger']

  • 0
    •  Analog Employees 
    on Feb 3, 2021 9:20 PM in reply to Wireless

    ok that seems fine.

    Can you add this call too: