2
$\begingroup$

I encountered with the "No module named 'gnuradio'" error while I was trying to run GnuRadio python code in my python web server.

enter image description here

And this is my gnuRadio generated code:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Exercise 1
# GNU Radio version: 3.7.13.5
##################################################

from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import osmosdr
import time


class Exercise_1(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self, "Exercise 1")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10000000
        self.channel_width = channel_width = 200e3
        self.channel_freq = channel_freq = 96.5e6
        self.center_freq = center_freq = 97.9e6

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
                interpolation=12,
                decimation=5,
                taps=None,
                fractional_bw=None,
        )
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)

        self.low_pass_filter_0 = filter.fir_filter_ccf(int(samp_rate / channel_width), firdes.low_pass(
            1, samp_rate, 75e3, 25e3, firdes.WIN_HAMMING, 6.76))
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.audio_sink_0 = audio.sink(48000, '', True)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
            quad_rate=480e3,
            audio_decimation=10,
        )
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, center_freq - channel_freq, 1, 0)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_wfm_rcv_0, 0), (self.audio_sink_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.osmosdr_source_0.set_sample_rate(self.samp_rate)
        self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 75e3, 25e3, firdes.WIN_HAMMING, 6.76))
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)

    def get_channel_width(self):
        return self.channel_width

    def set_channel_width(self, channel_width):
        self.channel_width = channel_width

    def get_channel_freq(self):
        return self.channel_freq

    def set_channel_freq(self, channel_freq):
        self.channel_freq = channel_freq
        self.analog_sig_source_x_0.set_frequency(self.center_freq - self.channel_freq)

    def get_center_freq(self):
        return self.center_freq

    def set_center_freq(self, center_freq):
        self.center_freq = center_freq
        self.osmosdr_source_0.set_center_freq(self.center_freq, 0)
        self.analog_sig_source_x_0.set_frequency(self.center_freq - self.channel_freq)


def main(top_block_cls=Exercise_1, options=None):

    tb = top_block_cls()
    tb.start()
    try:
        raw_input('Press Enter to quit: ')
    except EOFError:
        pass
    tb.stop()
    tb.wait()


if __name__ == '__main__':
    main()

I tried to figure out the cause of this error but no luck. I even removed Pybombs and reinstall it again but kept getting the same error.

Any clues to solve this error would be highly appreciated.

Update:

I appreciate your help "fmagno". Again, I removed/cleaned everything and tried to follow the instructions you recommended, but I am stuck with the below error whenever I run pybombs auto-config.

The error is:

PyBOMBS.RecipeListManager - ERROR - '/home/fit-pc/.pybombs/recipes/gr-recipes' is not a directory.

enter image description here

Update:

Fmagno, I just finished re-installation and made sure that pybombs prefix is activated by running source setup_env.sh before using gnuradio, but it did solve the main problem.

enter image description here

enter image description here

$\endgroup$
3
$\begingroup$

I found the solution to my problem. It was due to running my program using Python3, while as Marcus Muller stated in my other posting "GNU Radio 3.7 is not python3 compatible". So, using Python2.7 instead was the solution.

$\endgroup$
2
$\begingroup$

@Hadad, maybe you are not activating your pybombs prefix by running source setup_env.sh before using gnuradio?

Documentation for details: https://wiki.gnuradio.org/index.php/InstallingGR#Using_PyBOMBS

Once activated you should be able to import gnuradio within a python console without errors:

$ python
>>> import gnuradio
$\endgroup$
  • $\begingroup$ I appreciate your help. Again, I removed/cleaned everything and tried to follow the instructions you recommended, but I am stuck with the below error whenever I run pybombs auto-config. The error is: PyBOMBS.RecipeListManager - ERROR - '/home/fit-pc/.pybombs/recipes/gr-recipes' is not a directory. $\endgroup$ – Hadad Jul 11 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.