Cython + setuptools not working with .pyx,only with .c-files

Discussion in 'Python' started by Diez B. Roggisch, Aug 6, 2009.

  1. Hi,


    I'm trying to build a Cython-extension as Egg.

    However, this doesn't work - I can either use distutils to build the
    extension, creating a myextension.c-file on the way.

    If that's there, I can use setuptools to build the egg.

    But when I remove the .c-file, the .pyx-file isn't used to re-generate it.

    This is my setup.py:

    ----
    import os
    import glob
    from setuptools import setup, Extension
    #from distutils.core import setup
    #from distutils.extension import Extension

    from Cython.Distutils import build_ext


    objs = [...] # a static lib I want to wrap

    setup(
    name='MyExtension',
    version="0.1",
    description='',
    author='Diez B. Roggisch',
    author_email='...',
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("myextension", ["myextension.pyx"],
    libraries=["crypto"],
    extra_objects = objs)],

    -----


    I can of course check in the myextension.c-file , and then when actually
    working on the extension create it new by uncommenting the above lines.

    But I guess that's not really the way things should work...

    Diez
     
    Diez B. Roggisch, Aug 6, 2009
    #1
    1. Advertising

  2. On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggisch<> wrote:
    > Hi,
    >
    >
    > I'm trying to build a Cython-extension as Egg.
    >
    > However, this doesn't work - I can either use distutils to build the
    > extension, creating a myextension.c-file on the way.
    >
    > If that's there, I can use setuptools to build the egg.
    >
    > But when I remove the .c-file, the .pyx-file isn't used to re-generate it.
    >
    > This is my setup.py:
    >
    > ----
    > import os
    > import glob
    > from setuptools import setup, Extension
    > #from distutils.core import setup
    > #from distutils.extension import Extension
    >
    > from Cython.Distutils import build_ext


    What happens if you import setuptools *after* Cython.distutils ? My
    guess - I could be wrong - is that both Cython.distutils and
    setuptools monkey-patch distutils, and that setuptools does not "see"
    Cython.Distutils. It could also be an incompatibility between
    Cython.Distutils and setuptools (the design of distutils forces you to
    take into account the details of things modified by every distutils
    extension).

    cheers,

    David
     
    David Cournapeau, Aug 6, 2009
    #2
    1. Advertising

  3. David Cournapeau schrieb:
    > On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggisch<> wrote:
    >> Hi,
    >>
    >>
    >> I'm trying to build a Cython-extension as Egg.
    >>
    >> However, this doesn't work - I can either use distutils to build the
    >> extension, creating a myextension.c-file on the way.
    >>
    >> If that's there, I can use setuptools to build the egg.
    >>
    >> But when I remove the .c-file, the .pyx-file isn't used to re-generate it.
    >>
    >> This is my setup.py:
    >>
    >> ----
    >> import os
    >> import glob
    >> from setuptools import setup, Extension
    >> #from distutils.core import setup
    >> #from distutils.extension import Extension
    >>
    >> from Cython.Distutils import build_ext

    >
    > What happens if you import setuptools *after* Cython.distutils ? My
    > guess - I could be wrong - is that both Cython.distutils and
    > setuptools monkey-patch distutils, and that setuptools does not "see"
    > Cython.Distutils. It could also be an incompatibility between
    > Cython.Distutils and setuptools (the design of distutils forces you to
    > take into account the details of things modified by every distutils
    > extension).


    Tried that, nothing changed :(

    Diez
     
    Diez B. Roggisch, Aug 7, 2009
    #3
  4. On Fri, Aug 7, 2009 at 7:09 PM, Diez B. Roggisch<> wrote:

    >
    > Tried that, nothing changed :(


    Then you will have to modify Cython.Distutils to be aware of
    setuptools, I think (and soon Distribute... ).

    David
     
    David Cournapeau, Aug 7, 2009
    #4
  5. Diez B. Roggisch wrote:
    > I'm trying to build a Cython-extension as Egg.
    >
    > However, this doesn't work - I can either use distutils to build the
    > extension, creating a myextension.c-file on the way.
    >
    > If that's there, I can use setuptools to build the egg.
    >
    > But when I remove the .c-file, the .pyx-file isn't used to re-generate it.


    setuptools monkeypatch into distutils to support Pyrex if it's installed,
    but most non-bleeding-edge versions do not know about Cython and thus break
    the Cython distutils support when Pyrex isn't there as well.

    What helps is to put a fake Pyrex installation into your sys.path, like

    http://codespeak.net/svn/lxml/trunk/fake_pyrex/

    as done at the top of

    http://codespeak.net/svn/lxml/trunk/setup.py

    I haven't tried if newer setuptools versions have been fixed yet.

    Stefan
     
    Stefan Behnel, Aug 7, 2009
    #5
  6. Stefan Behnel wrote:

    > Diez B. Roggisch wrote:
    >> I'm trying to build a Cython-extension as Egg.
    >>
    >> However, this doesn't work - I can either use distutils to build the
    >> extension, creating a myextension.c-file on the way.
    >>
    >> If that's there, I can use setuptools to build the egg.
    >>
    >> But when I remove the .c-file, the .pyx-file isn't used to re-generate
    >> it.

    >
    > setuptools monkeypatch into distutils to support Pyrex if it's installed,
    > but most non-bleeding-edge versions do not know about Cython and thus
    > break the Cython distutils support when Pyrex isn't there as well.
    >
    > What helps is to put a fake Pyrex installation into your sys.path, like
    >
    > http://codespeak.net/svn/lxml/trunk/fake_pyrex/
    >
    > as done at the top of
    >
    > http://codespeak.net/svn/lxml/trunk/setup.py


    Thanks, that did the trick for us.

    Diez
     
    Diez B. Roggisch, Aug 10, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Novak
    Replies:
    0
    Views:
    457
    Greg Novak
    Nov 18, 2004
  2. Ronny Mandal

    PyX custom x-labels

    Ronny Mandal, May 8, 2006, in forum: Python
    Replies:
    0
    Views:
    296
    Ronny Mandal
    May 8, 2006
  3. Tom Longridge

    PyX on Windows

    Tom Longridge, May 13, 2006, in forum: Python
    Replies:
    0
    Views:
    587
    Tom Longridge
    May 13, 2006
  4. =?UTF-8?B?U3RlZmFuIFNjaHfDpHJ6bGVy?=

    PyX in Console and Script IDE

    =?UTF-8?B?U3RlZmFuIFNjaHfDpHJ6bGVy?=, Apr 12, 2007, in forum: Python
    Replies:
    0
    Views:
    256
    =?UTF-8?B?U3RlZmFuIFNjaHfDpHJ6bGVy?=
    Apr 12, 2007
  5. per
    Replies:
    11
    Views:
    1,296
    S Arrowsmith
    Mar 9, 2009
Loading...

Share This Page