# Error in Python file generated by GnuRadio Companion

**URL:** <https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885>\
**Category:** GNU Radio\
**Created:** [January 9, 2015, 3:19pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885 "2015-01-09T15:19:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [January 9, 2015, 3:19pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/1 "2015-01-09T15:19:03Z")

</div>

Hello,

I have created My QPSK Demodulator following tutorial 4:  
[https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorial\_GNU\_Radio\_in\_C++](https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorial_GNU_Radio_in_C++)

My source files (C++, XML) look exactly like those in the repository and  
the build and installation produced the same output as shown in the  
tutorial.

I have created a .gnuradio/config.conf file in my home directory so that  
I could add the XML installation file to GRC search path:

[grc]  
local\_blocks\_path=/usr/local/share/gnuradio/grc/blocks

My QPSK Demodulator appears correctly in GRC and I could connect the  
block in the attached GRC application (source and screenshot attached).

However, when I click on the “Generate the flow graph” button, the  
Python file generated has the following lines:

self.tutorial\_my\_qpsk\_demod\_cb\_0 = --------\>  
cannot find ‘Gray\_code’: tutorial.my\_qpsk\_demod\_cb($Gray\_code)  
\<--------

And if I execute the graph, the following error happens, unsurprisingly:

Executing: “/home/dpi/projects/seethroughwalls/CHa/mpsk\_stage6.py”

File “/home/dpi/projects/seethroughwalls/CHa/mpsk\_stage6.py”, line  
197  
self.tutorial\_my\_qpsk\_demod\_cb\_0 = --------\>  
^  
SyntaxError: invalid syntax

My configuration:

Ubuntu 14.04  
GNU Radio Companion 3.7.2.1  
GNU Radio 3.7.2.1

All installed via Ubuntu packages.

I am sure this is a simple thing, but unfortunately my investigations so  
far have been unsuccessful. Any help would be appreciated.

Best regards,  
Damien

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 9, 2015, 3:28pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/2 "2015-01-09T15:28:21Z")

</div>

* * *

Discuss-gnuradio mailing list  
removed\_email\_address@domain.invalid  
[https://lists.gnu.org/mailman/listinfo/discuss-gnuradio](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 9, 2015, 3:37pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/3 "2015-01-09T15:37:38Z")

</div>

Dear Sebastian,

Thank you very much for your help.

I checked my XML block file and it uses gray\_code with lower ‘g’, this  
is why I don’t understand why GRC generates a Python code with upper G.  
Moreover, the Pythong code generated by GRC calls the Demodulator, hence  
it should pass the parameter value like it does for the other blocks,  
not its name or am I wrong ?

Here is my block XML:

\<?xml version="1.0"?\> My QPSK Demodulator tutorial\_my\_qpsk\_demod\_cb Tutorial import tutorial tutorial.my\_qpsk\_demod\_cb($Gray\_code) Gray Code gray\_code ...

Thanks again,  
Damien

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 9, 2015, 3:43pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/4 "2015-01-09T15:43:12Z")

</div>

On 01/09/2015 03:36 PM, PIGUET Damien wrote:

> ```
> <name>Gray Code</name>
> <key>gray_code</key>
> 
> ```
> 
> …

GRC uses whatever you put in to create the python code. Yours  
still reads

tutorial.my\_qpsk\_demod\_cb($Gray\_code)

instead of

tutorial.my\_qpsk\_demod\_cb($gray\_code)

which is why GRC can’t replace the template variable “$_G_ray\_code”. It  
is undefined.

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 9, 2015, 4:00pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/5 "2015-01-09T16:00:34Z")

</div>

Oh sorry I was looking at the wrong line. Now it works, thanks!

Damien

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 9, 2015, 4:32pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/6 "2015-01-09T16:32:13Z")

</div>

Was this code you wrote, or is it from gr-tutorial?

M

---

<div class="post-metadata">

**Author:** ![PIGUET\_Damien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@PIGUET\_Damien](https://www.ruby-forum.com/u/PIGUET_Damien)\
**Post date:** [January 12, 2015, 5:04pm UTC](https://www.ruby-forum.com/t/error-in-python-file-generated-by-gnuradio-companion/234885/7 "2015-01-12T17:04:10Z")

</div>

Hi Martin, and thank you for your help.

The answer is gr-tutorial.

Thanks to the correction suggested by Sebastian I can go beyond this  
step, but then GRC fails to find the library compiled and installed  
following the instructions in the tutorial:

File  
“/usr/local/lib/python2.7/dist-packages/tutorial/tutorial\_swig.py”, line  
24, in swig\_import\_helper  
\_mod = imp.load\_module(’\_tutorial\_swig’, fp, pathname, description)  
ImportError: libgnuradio-tutorial.so: cannot open shared object file: No  
such file or directory

Note: the installer (sudo make install) put the library in:  
/usr/local/lib/

If you have a hint, thanks for letting me know.

Best regards,  
Damien
