Problem mit python-pmw

Hallo Gemeinde,

das in Spyder aufgerufene Programm (aus: H. P. Langtangen, Python Scripting for Computational Science, Third edition):

#!/usr/bin/env python
“”“Simple demo of the Pmw.Blt.Graph widget.”""
import Pmw, Tkinter, string, random

class BltDemo1:
def init(self, parent):
self.master = parent
self.ncurves = 3 # number of curves
self.npoints = 20 # number of points on each curve

    # it is advantegous to store (x,y) data in
    # Pmw.Blt.Vector objects
    
    # use one x vector to hold the x coordinates of all
    # the self.ncurves curves:
    self.vector_x = Pmw.Blt.Vector()
    # use a list of y vectors(0:self.ncurves-1):
    self.vector_y = [Pmw.Blt.Vector() for y in range(self.ncurves)]
    self.fill_vectors()  # fill the vectors with data for testing

    # make graph widget:
    self.g = Pmw.Blt.Graph(self.master, width=500, height=300)
    self.g.pack(expand=True, fill='both')

    # define a list of colors for the various curves:
    colors = 'red','yellow','blue','green','black','grey']

    # plot each curve:
    # the x coordinates are in self.vector_x
    # the y coordinates are in self.vector_y*

    for i in range(self.ncurves):
        curvename = 'line' + str(i)
        self.g.line_create(
            curvename,              # used as identifier
            xdata=self.vector_x,    # x coords
            ydata=self.vector_y*, # y coords
            color=colors*,        # linecolor
            linewidth=1+i,          # (progressively thicker lines)
            dashes='',              # '': solid, number: dash
            label=curvename,        # legend
            symbol='',              # no symbols at data points
            )
    self.g.configure(title='My first BLT plot')
    self.g.yaxis_configure(min=0, max=8)        
    self.buttons = Pmw.ButtonBox(self.master,
                                 labelpos='n',
                                 label_text='Options:')
    self.buttons.pack(fill='both', expand=True, padx=10, pady=10)
    # add buttons:
    self.buttons.add('Move points',command=self.animate)
    self.buttons.add('Postscript', command=self.postscript)
    self.buttons.add('Grid on',    command=self.g.grid_on)
    self.buttons.add('Symbols',    command=self.symbols)
    self.buttons.add('Smooth',     command=self.smooth)
    self.buttons.add('Quit',       command=self.master.quit)
    self.buttons.alignbuttons() # nice loook...

def symbols(self):
    """Turn on symbols (diamonds) at all points."""
    # get the names(identifiers) of all curves in the graph:
    curvenames = self.g.element_show()
    # foreach curve, add a diamond symbol, filled with the
    # color of the curve ('defcolor') and with a size of 2:
    for curvename in curvenames:
        self.g.element_configure(curvename, symbol='diamond',
                                 outlinewidth=2, fill='defcolor')

def smooth(self):
    """Smooth the curves by cubic spline interpolation."""
    for curvename in self.g.element_show():
        self.g.element_configure(curvename, smooth='natural')

def fill_vectors(self):
    """Fill Pmw.Blt vectors with (random) values."""
    # use random numbers for generating plot data:
    random.seed(9)                    # fix the seed for testing
    for index in range(self.npoints):
        self.vector_x.append(index)   # x coordinates
        for y in range(self.ncurves):
            self.vector_y[y].append(random.uniform(0,8))

def animate(self,delay=100):
    """Adjust curves randomly, in an animated fashion."""
    curves = self.g.element_show()
    for index in range(self.npoints):
        for y in range(self.ncurves):
            self.vector_y[y][index] = random.uniform(0,8)
            # changing vector_y[y] affects the graph directly,
            # but not until the function returns
            # introduce a delay and call update (to force Tk to update
            # pending events, i.e., here the graph)
            self.master.after(delay)
            self.master.update()
    
def postscript(self):
    """Generate a hardcopy of the plot in PostScript."""
    self.g.postscript_output(fileName='tmp2.ps',decorations='no')

if name == ‘main’:
root = Tkinter.Tk()
Pmw.initialise(root)
import scitools.misc; scitools.misc.fontscheme1(root) # our own fonts…
root.title(‘Simple Pmw.Blt.Graph demo’)
blt = BltDemo1(root)
root.mainloop()

bricht nur in openSuSE 13.2, nicht in Ubuntu Mate 14.04, nicht in LMDE Mate 2 (Betsy) ab mit der Meldung

Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC]
Type “copyright”, “credits” or “license” for more information.

IPython 2.2.0 – An enhanced Interactive Python.
? → Introduction and overview of IPython’s features.
%quickref → Quick reference.
help → Python’s own help system.
object? → Details about ‘object’, use ‘object??’ for extra details.
%guiref → A brief reference about the graphical user interface.

In [1]: runfile(’/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui/plotdemo_blt.py’, wdir=’/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui’)
Traceback (most recent call last):

File “<ipython-input-1-b712a1e5d8a6>”, line 1, in <module>
runfile(’/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui/plotdemo_blt.py’, wdir=’/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui’)

File “/usr/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py”, line 580, in runfile
execfile(filename, namespace)

File “/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui/plotdemo_blt.py”, line 105, in <module>
blt = BltDemo1(root)

File “/run/media/hb/FLASHKEY/Python/Langtangen/scripting/src/py/gui/plotdemo_blt.py”, line 16, in init
self.vector_x = Pmw.Blt.Vector()

File “/usr/lib/python2.7/site-packages/Pmw/Pmw_1_3_3/lib/PmwBlt.py”, line 110, in init
self.tk.call(_vectorCommand, ‘create’, self._name)

TclError: invalid command name “::blt::vector”

Ich schicke diese Mitteilung an Euch, obwohl der Fehler auch in Python, d.h. in python-pmw oder in python-scitools stecken kann oder in KDE - keine Ahnung.

Grüße
Helmut Büch.***

Es kann “::blt::vector” nicht aufgerufen werden. Ich würde als Erstes die einzelnen aufgelisteten Skripte in der Fehlermeldung überprüfen, ob sie ausführbar sind und ich (als Benutzer) auch die Rechte dazu habe. Anschließend würde ich die entsprechenden Zeilen im Code untersuchen.

Bitte verwende in Zukunft bei Code Code-Tags. Diese findest Du beim Thread-Editor oben mit einer Raute in der Leiste. Das macht alles lesbarer.