# Running flowgraphs from command line

**URL:** <https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293>\
**Category:** GNU Radio\
**Created:** [September 7, 2015, 6:31pm UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293 "2015-09-07T18:31:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [September 7, 2015, 6:31pm UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293/1 "2015-09-07T18:31:09Z")

</div>

Hi everybody,

I installed GNURadio on a fresh machine with Mac OS X 10.10.5 via  
MacPorts. I now have 2 Python installs in /usr/bin, python2.6 and  
python2.7. Running flowgraphs with GRC is no problem. However, when  
trying to run a .py-file from the terminal, as suggested in the guided  
tutorial 3.1 („if else“) some modules are not found:

Patricks-iMac:work patrick$ python if\_else\_mod.py  
Traceback (most recent call last):  
File “if\_else\_mod.py”, line 18, in   
from PyQt4 import Qt  
ImportError: No module named PyQt4

Why does it work, when running the file from GRC? Is my terminal using  
the wrong python install? How could I change that? I also tried changing  
the path variable on my notebook a few days ago, when I ran into the  
same problem. But since I am new to python and the command line I  
obviously made a mistake so that at some point I could not start the GRC  
anymore. So your help is appreciated and needed. Couldn’t find a similar  
question in the archives.

Thank you.  
Patrick

---

<div class="post-metadata">

**Author:** ![Patrick\_KrS\_mer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@Patrick\_KrS\_mer](https://www.ruby-forum.com/u/Patrick_KrS_mer)\
**Post date:** [September 7, 2015, 7:14pm UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293/2 "2015-09-07T19:14:23Z")

</div>

Hi Patrick,

I think I might have the answer, although Michael D. could  
certainly provide better explanations and all that.

You need to check your environment variables. You can do that in the  
command line by typing “env”.  
Normally you should see something like  
"  
PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Version/2.7/lib/python2.7/site-packages/:/opt/local/lib/:/usr/local/lib/  
"  
in the output.  
Normally Macports should adapt your ~/.profile file in order to tell  
your system where Macports put the stuff you installed.

If for some reasons that fails, your PYTHONPATH (in this case) will not  
point to the correct directories.

If that indeed is the case, then you might insert some lines to your  
~/.profile file, i.e.

“export  
PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/:/opt/local/lib/:/usr/local/lib/:$PYTHONPATH”

and

“export PATH=”/opt/local/bin:/opt/local/sbin:$PATH""

at the end of that file.

You might want to make sure that you can find PyQT4 yourself in those  
given directories. For example my PyQT4 folder is under

“/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages”

After you inserted those lines to your .profile, you just need to open a  
new terminal, and you can again check via “env” if that worked out.

Regards,  
Kevin

Am 07.09.15 um 18:29 schrieb Patrick Krmer:

---

<div class="post-metadata">

**Author:** ![Patrick\_KrS\_mer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@Patrick\_KrS\_mer](https://www.ruby-forum.com/u/Patrick_KrS_mer)\
**Post date:** [September 8, 2015, 3:05am UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293/3 "2015-09-08T03:05:51Z")

</div>

Hi Patrick - So what’s happening is that with GRC, because it was  
installed via MacPorts the MP version of Python is used. The terminal  
only knows what you tell it via environment variables such as PYTHONPATH  
(already suggested by Kevin Hofschröer) and PATH. In your case right  
now, I’ll bet that the PATH contains /usr/bin before /opt/local/bin (if  
the latter is listed at all). If you do “which python”, you’ll see what  
your shell is executing when you type “python” (again, better  
/usr/bin/python [2.7 something]). Even if you add /opt/local/bin at the  
start of PATH, you might still need to tell MP to select the version of  
Python you want to use when you type “python” in the shell. You can list  
the options port has via “port select --list python”, and then select  
Python 2.7 via “sudo port select python python27” if it not already  
active. Combining this with making sure /opt/local/bin comes first in  
PATH should solve your issue. Hope this helps! - MLD

---

<div class="post-metadata">

**Author:** ![Patrick\_KrS\_mer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@Patrick\_KrS\_mer](https://www.ruby-forum.com/u/Patrick_KrS_mer)\
**Post date:** [September 8, 2015, 9:35am UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293/4 "2015-09-08T09:35:32Z")

</div>

Hey Michael, Hey Kevin, Hey all,

thanks for your help!  
I found that by specifying the python version I want to use when running  
the file, everything works fine. Like this:

python2.7 if\_else\_mod.py

This would be acceptable for me, however, I decided to do some of the  
stuff you suggested. I get the following output when running env:

Patricks-iMac:~ patrick$ env  
TERM\_PROGRAM=Apple\_Terminal  
SHELL=/bin/bash  
TERM=xterm-256color  
TMPDIR=/var/folders/3j/qy7\_9bpx29g\_nf\_ymbkw\_td00000gn/T/  
Apple\_PubSub\_Socket\_Render=/private/tmp/com.apple.launchd.11PeMdZFpD/Render  
TERM\_PROGRAM\_VERSION=343.7  
TERM\_SESSION\_ID=1FC9A988-7B1E-4869-95D3-5FF71F9942F7  
USER=patrick  
SSH\_AUTH\_SOCK=/private/tmp/com.apple.launchd.0PyXsYlSwi/Listeners  
\_\_CF\_USER\_TEXT\_ENCODING=0x1F5:0x0:0x3  
PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin  
PWD=/Users/patrick  
DBUS\_LAUNCHD\_SESSION\_BUS\_SOCKET=/private/tmp/com.apple.launchd.dJkzL2MOo1/unix\_domain\_listener  
LANG=de\_DE.UTF-8  
XPC\_FLAGS=0x0  
XPC\_SERVICE\_NAME=0  
SHLVL=1  
HOME=/Users/patrick  
LOGNAME=patrick  
DISPLAY=/private/tmp/com.apple.launchd.KWH6aSklFz/org.macosforge.xquartz:0  
\_=/usr/bin/env

I see that I only have a PATH variable set, but no PYTHONPATH. And  
/opt/local/bin seems to be the first in place?! With

Patricks-iMac:bin patrick$ pwd  
/usr/bin  
Patricks-iMac:bin patrick$ ./py  
pydoc python python2.6-config pythonw  
pydoc2.6 python-config python2.7 pythonw2.6  
pydoc2.7 python2.6 python2.7-config pythonw2.7

I see that I have even more python installs. Now I ran

Patricks-iMac:bin patrick$ which python  
/usr/bin/python  
Patricks-iMac:bin patrick$ port select --list python  
Available versions for python:  
none (active)  
python26-apple  
python27  
python27-apple

So terminal normally would run “python” (didn’t look up the version).  
And MacPorts?  
All this is what comes out of a clean OS X 10.9 install with an update  
to 10.10 and then a GNURadio install via MacPorts. Didn’t try yet to  
change one of the env variables or use the 'sudo port select python  
python27‘ command. What would your suggestions now be? What I don’t  
understand is why I have to tell MacPorts to use python2.7, if in fact I  
want to tell that to my terminal?

Thanks & Regards  
Patrick

---

<div class="post-metadata">

**Author:** ![Patrick\_KrS\_mer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@Patrick\_KrS\_mer](https://www.ruby-forum.com/u/Patrick_KrS_mer)\
**Post date:** [September 8, 2015, 3:23pm UTC](https://www.ruby-forum.com/t/running-flowgraphs-from-command-line/243293/5 "2015-09-08T15:23:42Z")

</div>

Hi Patrick - You’re on the right track. We’re just following what is  
written (roughly) in  
\< [http://gnuradio.org/redmine/projects/gnuradio/wiki/MacInstall](http://gnuradio.org/redmine/projects/gnuradio/wiki/MacInstall) \>.  
Please also note that unless you play some tricks with the +quartz  
variant that is available many GR dependencies, you’ll have to install  
XQuartz.app to get any GUI working (see  
also [http://gnuradio.org/redmine/projects/gnuradio/wiki/MacInstall#Prerequisite-X11app-recommended-via-XQuartz](http://gnuradio.org/redmine/projects/gnuradio/wiki/MacInstall#Prerequisite-X11app-recommended-via-XQuartz) ).  
Your shell env looks good; because MP’s Python internally set their  
PYTHONPATH, you won’t need to so long as you use MP-provided GR projects  
(e.g., gr-fosphor). If you want to do your own out-of-tree builds, you  
can install them pretty much anywhere so long as the libraries are  
linked correctly and PYTHONPATH is set correctly to wherever your OOT  
Python module is installed.

You ask a variety of questions about Python usage in OSX. Apple provides  
Python 2.6 and 2.7 in /usr/bin in most modern OSX versions; in MP, you  
can get Python 2.7, 3.4, and 3.5rc3. MP does not provide the other  
Python versions because there really is no use case for them any longer  
: 2.7 supersedes 2.6, just as 3.4 does with 3.[0-3]; 3.5 when it is  
released should supersede 3.4, so we’ll likely push end users to

As to your question as to which ‘python’ is selected for use and when:  
The times it matters is when ‘python’ is issued either in a shell or in  
a script via “env python”. In this case, the first ‘python’ found in the  
shell PATH is used. Thus, issuing “sudo port select python python27”  
means that, more often than not, ‘python’ will result in the MP version  
(2.7) being executed. Which in general is OK. When you need to use the  
OSX system one you can always do that by either removing /opt/local/bin  
from PATH or by specifying “env /usr/bin/python”; there are other ways  
too. But, as a general use-case having “which python” result in  
/opt/local/bin/python is not a bad idea.

-That said-, you should never rely on a specific “python” being the one  
you expect it to be. If you want a specific Python, you’ll red to test  
for it or just specify it up front, e.g., “/opt/local/bin/python2.7”.

Hope this continues to help! - MLD
