[Tutor] GNUPLOT

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Apr 21 21:56:43 CEST 2005


> Yeah, it looks like Joshua Pollack ran into this issue three years ago:
>
>     http://mail.python.org/pipermail/tutor/2002-September/017579.html
>
> I'm going through the archive now to see if he was able to resolve the
> problem ok.

Hi Ray,

Yikes, it looks like someone never really answered Joshua when he brought
up that question.  Ugh.  Let's fix this now.


My best guess right now is that the module can't find the gnuplot command.

'gp_win32' uses the popen() command to try to connect to the underlying
gnuplot engine, and if it's given a command that it doesn't know about,
we'll get the same kind of errors that you're seeing:

#######
>>> import os
>>> test = os.popen("foobar", "w")
>>> sh: line 1: foobar: command not found

>>>
#######

It's a bit disappointing that Python doesn't raise an exception at this
point.  I wonder if that can be fixed.

Anyway, after this point, all bets are off, and even if 'test' is some
kind of object, it doesn't behave well at all:

#######
>>> test
<open file 'foobar', mode 'w' at 0x60a60>
>>> test.write("hello world")
>>> test.flush()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 32] Broken pipe
#######


I'm on a Unix system, so the exact error looks a bit different from yours,
but I think that the fundamental problem is the same: the module will emit
exceptions when it actually starts to try talking to gnuplot, rather than
at the point of initialization.

It makes for a slightly confusing error message situation, since the error
about not finding gnuplot should have been reported earlier.


By default, gp_win32.py tries to use the command 'pgnuplot.exe' as the
gnuplot command:

###### (Within gp_win32.py)
    gnuplot_command = r'pgnuplot.exe'
######

So check to see if you can access the command 'pgnuplot.exe' from your
command line from anywhere.  If not, then that's the problem, and you'll
probably want to put pgnuplot.exe in your PATH somewhere.  Either that, or
manually munge up gp_win32.py so that it explicitely points to the
pgnuplot.exe binary with its full path.



You might not have pgnuplot.exe if you're running an older version of
Gnuplot.  Do you know what version of Gnuplot you have?  If you have one
whose version is < 3.7.1, then you probably need to grab pgnuplot.exe from
the gnuplot FTP site here:

    ftp://ftp.gnuplot.info/pub/gnuplot/testing/windows-stdin.zip

(Taken from the README.txt in the Python gnuplot module.)

But since that file is just C source code, it might just be best to make
sure you're running the latest version of Gnuplot, since it should include
pgnuplot.exe now.


If you have any questions, please feel free to ask.  I hope this helps!



More information about the Tutor mailing list