[Pyrex] [Mac Inter Core Duo OS 10.4.9 ] Next question: cmd line build of init

Francesc Altet faltet at carabos.com
Wed Jun 6 16:37:05 UTC 2007


[Please always reply to the list so that other people and help/learn
to/from you]

El dc 06 de 06 del 2007 a les 08:51 -0700, en/na David Goldsmith va
escriure:
> OK, here's my pyx (which pyrexc-s, compiles, and loads fine):
> 
> # SolveSAC_Wrap.pyx
> 
> import BMMain as BMM
> 
> test_vals = BMM.BMGlobalInputsWrapper()
> test_vals.getAllInputs("/Users/dg/Documents/NOAA/Projects/BaroModes/software/BMSettingsFile.asc")
> 
> cdef public long GetNumVertices():
>     if test_vals.nodes:
>         return test_vals.d.getNrows()
> 
> Here's my runner:
> 
> import SolveSAC_Wrap as SSW
> 
> print SSW.GetNumVertices()

The problem is that you have defined GetNumVertices() as 'cdef' function
instead of 'def'.  'cdef' is the way to declare C functions but these
will not be callable from Python. Try this:

def GetNumVertices():
    if test_vals.nodes:
        return test_vals.d.getNrows()

better.

> 
> I haven't yet tried to write a setup.py because, in trying to 
> debug/understand the problem myself, I messed w/ the Setup.py in the 
> Demos - stupidly forgetting to back-up the original first - and now that 
> doesn't "work" either, producing stuff which also causes the same 
> ImportError, so I'm not sure what to do vis-a-vis writing a successful 
> setup.py, and reinstalling Pyrex is too big of a distraction at this 
> point unless absolutely necessary.

Installing Pyrex is pretty simple. When you will be more used to install
larger Python packages (for ex. PyTables or, still better, SciPy) you
will see what I mean ;)

> As an aside (perhaps; perhaps it's on point) in the Demos, exactly what 
> is the function of the pyprimes.py file (which seems to more or less 
> duplicate the primes.pyx file) and why doesn't the spam demo have a 
> similar "companion"?  Does it have to do with the fact that the spam 
> demo defines a class with a __new__ method but the primes demo doesn't, 
> and if so, is this relevant to the "missing init" problem I'm 
> experiencing?  (I note that I'm not presently defining a class - I tried 
> that as a soln. to my problem, but it had no effect).

I guess that pyprimes.py is there just because for speed comparison
purposes. In the case of spam.pyx the intention was to show how to work
with classes with Pyrex and the author didn't intend to do a direct
speed comparison in this case, so this is probably why he didn't added
the Python equivalent.

Cheers,

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth




More information about the Pyrex mailing list