Post Go back to editing

pyadi-iio : iio has no attribute Context


When I try to import the adi Python module I get the following error

>>> import adi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/adi/", line 34, in <module>
from adi.ad936x import ad9361, ad9363, ad9364, Pluto
File "/usr/lib/python3/dist-packages/adi/", line 34, in <module>
from adi.context_manager import context_manager
File "/usr/lib/python3/dist-packages/adi/", line 37, in <module>
class context_manager(object):
File "/usr/lib/python3/dist-packages/adi/", line 42, in context_manager
def ctx(self) -> iio.Context:
AttributeError: module 'iio' has no attribute 'Context'

I would be grateful to be pointed in the right direction here. Some further information is given below

Output of iio_info is shown below

$ iio_info -s
Library version: 0.23 (git tag: v0.23)
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=104400b839910016fbff2300d79a65fe2e [usb:3.6.5]
1: (Analog Devices PlutoSDR Rev.B (Z7010-AD9364)), serial=104400b839910016fbff2300d79a65fe2e [ip:pluto.local]

Also the PlutoSDR network interface has been detected as shown below

$ ip a

7: enx00e022d09a5c: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 00:e0:22:d0:9a:5c brd ff:ff:ff:ff:ff:ff
inet brd scope global dynamic noprefixroute enx00e022d09a5c
valid_lft 861784sec preferred_lft 861784sec
inet6 fe80::8efe:af5b:2260:286e/64 scope link noprefixroute
valid_lft forever preferred_lft forever

I am using Debian/Bullseye with following version of Python packages

pyadi-iio : Built from git (last commit on 2021-12-16)
python3-libiio : version 0.23 (backported from Debian/unstable)

  • A bit more information showing that iio is indeed missing the "Context" attribute

    >>> import iio
    >>> dir(iio)
    ['DEFAULT_BUFFER_SIZE', '__builtins__', '__cached__', '__doc__', '__file__',
    '__loader__', '__name__', '__package__', '__path__', '__spec__',
    '_iio_pluto_sink_swig', '_iio_pluto_source_swig', '_iio_swig', 'attr_sink',
    'attr_sink_make', 'attr_sink_sptr', 'attr_source', 'attr_source_make',
    'attr_source_sptr', 'attr_updater', 'device_sink', 'device_sink_make',
    'device_sink_make_from', 'device_sink_sptr', 'device_source',
    'device_source_make', 'device_source_make_from', 'device_source_sptr',
    'fmcomms2_sink', 'fmcomms2_sink_f32c', 'fmcomms2_sink_f32c_make',
    'fmcomms2_sink_f32c_sptr', 'fmcomms2_sink_make', 'fmcomms2_sink_make_from',
    'fmcomms2_sink_sptr', 'fmcomms2_source', 'fmcomms2_source_f32c',
    'fmcomms2_source_f32c_make', 'fmcomms2_source_f32c_sptr', 'fmcomms2_source_make',
    'fmcomms2_source_make_from', 'fmcomms2_source_sptr', 'fmcomms5_sink', 'fmcomms5_sink_f32c',
    'fmcomms5_sink_f32c_make', 'fmcomms5_sink_f32c_sptr', 'fmcomms5_sink_make',
    'fmcomms5_sink_make_from', 'fmcomms5_sink_sptr', 'fmcomms5_source', 'fmcomms5_source_f32c',
    'fmcomms5_source_f32c_make', 'fmcomms5_source_f32c_sptr', 'fmcomms5_source_make',
    'fmcomms5_source_make_from', 'fmcomms5_source_sptr', 'high_res_timer_epoch',
    'high_res_timer_now', 'high_res_timer_now_perfmon', 'high_res_timer_tps', 'iio_math',
    'iio_math_gen', 'iio_math_gen_make', 'iio_math_gen_sptr', 'iio_math_make',
    'iio_math_sptr', 'iio_pluto_sink_swig', 'iio_pluto_source_swig', 'iio_swig',
    'modulo_const_ff', 'modulo_const_ff_make', 'modulo_const_ff_sptr', 'modulo_ff',
    'modulo_ff_make', 'modulo_ff_sptr', 'os', 'pluto_sink', 'pluto_sink_make',
    'pluto_sink_sptr', 'pluto_source', 'pluto_source_make', 'pluto_source_sptr',
    'power_ff', 'power_ff_make', 'power_ff_sptr', 'unicode_literals']
    >>> import os.path
    >>> print(os.path.abspath(iio.__file__))
  • After some investigation I found that the Debian package gr-iio was preventing the successful import of the iio module installed by the python3-libiio Debian package. After removing the gr-iio package the above reported error no longer occurs. A bug report to this effect has been filed with Debian.

    Though I have a working solution for now, seems like I can not use iio blocks in GNU radio and import iio module at the same time, as a result of this issue. If there is a way to have both working I would be grateful for any suggestion.