1

I am new to creating custom OOT blocks and I'm trying to make a lookup table block. I followed the official tutorial found here.

When I refresh blocks inside GNU Radio Companion and run, it outputs the following error:

Generating: '/home/matterhorn/gnu_radio/lookup_test.py'

Executing: /usr/bin/python3 -u /home/matterhorn/gnu_radio/lookup_test.py

Traceback (most recent call last):
  File "/home/matterhorn/gnu_radio/lookup_test.py", line 27, in <module>
    from gnuradio import DABPhaseRef
ImportError: cannot import name 'DABPhaseRef' from 'gnuradio' (/usr/lib/python3.10/site-packages/gnuradio/__init__.py)

>>> Done (return code 1)

It seems to me, that GRC cannot see modules in local site.

My question: how can I get GRC to import my module?

Here is the python file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2023 Staš Bucik.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#


import numpy as np
from gnuradio import gr

class lookupTable(gr.sync_block):
    """
    docstring for block lookupTable
    """
    def __init__(self):
        gr.sync_block.__init__(self,
            name="lookupTable",
            in_sig=None,
            out_sig=[(np.complex64, 2048)])
        
        self.kinTable = # long lookup table 
        
        self.timePhaseTable = # long lookup table 
        
        self.table = []
        for k in range(-1024, 1024):
            '''if k < -768 or k > 768 or k == 0:
                table[k + 1024] = 0. + 0.j
            else:
                kin = self.getKINParams(k)
                h = self.timePhaseTable[kin[1], k - kin[0]]
                phase = np.pi * 0.5 * (h + kin[2])
                table[k + 1024] = np.exp(1.j * phase)'''
            table[k + 1024] = k + 0.j

    def getKINParams(self, k):
        for row in self.kinTable:
            if k >= row[0] and k <= row[1]:
                return row[2:]
        raise Exception("No KIN parameters found!")

    def work(self, input_items, output_items):
        output_items[0] = self.table
        return len(output_items[0])

Here is the YAML file:

id: DABPhaseRef_lookupTable
label: lookupTable
category: '[DABPhaseRef]'

templates:
  imports: from gnuradio import DABPhaseRef
  make: DABPhaseRef.lookupTable()

#  Make one 'inputs' list entry per input and one 'outputs' list entry per output.
#  Keys include:
#      * label (an identifier for the GUI)
#      * domain (optional - stream or message. Default is stream)
#      * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
#      * vlen (optional - data stream vector length. Default is 1)
#      * optional (optional - set to 1 for optional inputs. Default is 0)


outputs:
- label: out0
  domain: stream
  dtype: complex
  vlen: 2048

#  'file_format' specifies the version of the GRC yml format used in the file
#  and should usually not be changed.
file_format: 1

When I build and install my module it succeeds:

Install the project...
-- Install configuration: "Release"
-- Up-to-date: /usr/local/lib/cmake/gnuradio-DABPhaseRef/gnuradio-DABPhaseRefConfig.cmake
-- Up-to-date: /usr/local/include/gnuradio/DABPhaseRef/api.h
-- Up-to-date: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.py
-- Up-to-date: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.py
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.pyc
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.pyc
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.pyo
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.pyo
-- Up-to-date: /usr/local/share/gnuradio/grc/blocks/DABPhaseRef_lookupTable.block.yml

As shown above, python module was installed into local directory (indicated by /usr/local/lib/).

Edit: I am using Manjaro linux. There is no PYTHONPATH defined. I tried exporting it in .bashrc, adding both paths (local and nonlocal). It did not fix my problem.

  • can you check whether `/usr/local/lib/python3.10/site-packages/` is part of your `PYTHONPATH` environment variable? – Marcus Müller Mar 06 '23 at 11:57
  • Yes it is, still not working. – Staš Bucik Mar 06 '23 at 12:14
  • what does `gnuradio-config-info --prefix` say? – Marcus Müller Mar 06 '23 at 12:21
  • It says `/usr/` – Staš Bucik Mar 06 '23 at 12:23
  • ah, OK. So, here's what I think is happening: When Python sees `from gnuradio import something`, it looks for the `gnuradio` module, finds it under `/usr/lib/python…` (notice: no `local`!), then looks inside for `something`. Which goes wrong, because that doesn't happen to be the place you've installed `something` (or, `DABPhaseRef` in your case) to. – Marcus Müller Mar 06 '23 at 12:25
  • Can you try first uninstalling your currently installed module (`sudo make uninstall`), then running `cmake` again, but this time adding the following `-DCMAKE_INSTALL_PREFIX=$(gnuradio-config-info --prefix` to the `cmake` command line? – Marcus Müller Mar 06 '23 at 12:26

1 Answers1

1

As Marcus Müller commented: Replace 3rd command in the official tutorial cmake .. with cmake -DCMAKE_INSTALL_PREFIX=$(gnuradio-config-info --prefix) ... Do not forget to uninstall previous builds.