# Creating and importing a new python block

**URL:** <https://www.ruby-forum.com/t/creating-and-importing-a-new-python-block/234311>\
**Category:** GNU Radio\
**Created:** [February 23, 2015, 4:57pm UTC](https://www.ruby-forum.com/t/creating-and-importing-a-new-python-block/234311 "2015-02-23T16:57:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [February 23, 2015, 4:57pm UTC](https://www.ruby-forum.com/t/creating-and-importing-a-new-python-block/234311/1 "2015-02-23T16:57:15Z")

</div>

Hello,

I tried to build my first custom block.  
Very easy. It just generates one tune msg every 5 seconds.

I followed steps of writing an OOT block in python:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules#Tutorial-3-Writing-a-signal-processing-block-in-Python](http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules#Tutorial-3-Writing-a-signal-processing-block-in-Python)

% gr\_modtool super\_msg\_generator  
super\_msg\_generator % gr\_modtool add -t sync -l python generador

Inside python/generador.py my code:

#!/usr/bin/env python  
import numpy  
from gnuradio import gr  
import time  
class generador(gr.sync\_block):  
def **init** (self):  
gr.sync\_block. **init** (self,  
name=“generador”  
#,in\_sig=[],  
#,out\_sig=[]  
)  
self.message\_port\_register\_out(pmt.intern(“ppm”))

```
def work(self):
while True:
    time.sleep(5)
    self.message_port_pub(pmt.intern("ppm"), pmt.to_pmt("freq",

```

float(915e6)))  
time.sleep(5)  
self.message\_port\_pub(pmt.intern(“ppm”), pmt.to\_pmt(“freq”,  
float(918e6)))

How can I check a block with no inputs and no outputs?

After that I created a build folder in gnuradio/gr-super\_msg\_generator

cmake …/  
make  
sudo make install  
sudo ldconfig

I thought that was everyhting.

However when trying to setup a python flowgraph the code cannot import  
the  
new block.

tune\_msg.py::  
#!/usr/bin/env python  
from gnuradio import blocks  
from gnuradio import eng\_notation  
from gnuradio import gr  
from gnuradio import uhd  
from gnuradio import super\_msg\_generator  
…

output when executing: $ python tune\_msg.py  
linux; GNU C++ version 4.7.2; Boost\_104900; UHD\_003.008.001-42-g8c87a524

Traceback (most recent call last):  
File “tune\_msg.py”, line 12, in   
from gnuradio import super\_msg\_generator  
ImportError: cannot import name super\_msg\_generator

There is something missing but I do not figure it out. Any help please?

Regards,
