[Pyrex] newbie question: error using pyrex
Lenard Lindstrom
len-l at telus.net
Thu Sep 20 01:31:42 CEST 2007
Christian Meesters wrote:
> Thanks,
>
> This is all valuable input I will consider. However, wenn compiling with
> the following setup script:
>
> from distutils.core import setup
> from distutils.extension import Extension
> from Pyrex.Distutils import build_ext
>
> setup(
> name = "pofr",
> ext_modules = [
> Extension("pofr", ["pofr_module3.pyx"])
> ],
> cmdclass = {'build_ext' : build_ext}
> )
>
> I'll get a bunch of warnings:
> pofr_module3.c: In function ‘__pyx_f_12pofr_module3_pofr’:
>
A clue is here.
[snip warnings]
> When calling the compiler directly:
> cmeesters:src cm$ gcc -c -fPIC -I/usr/include/python2.5/ pofr_module2.c
> cmeesters:src cm$ gcc -shared pofr_module2.o -o pofr.so
>
Here is the problem. You rename the extension module from pofr_module2
(3 ?) to just pofr.
Pyrex uses the original pyx file name to define the initialization
function. In this case the function would be initpofr_module3 according
to the setup file and the first warning I labeled as a clue.
> I don't get any warnings and the module is compiled (nice).
>
> However, import into python does not work for both scenarios:
> Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> import pofr
>>>>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: dynamic module does not define init function (initpofr)
>
> What am I missing now? And can anybody point me to the relevant
> documentation, in case I overlooked that part?
>
>
Python uses the module name, pofr, to determine the initialization
function name. It does not find it. Rename pofr_module3.pyx to pofr.pyx .
--
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list