Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cython + setuptools not working with .pyx,only with .c-files

Reply
Thread Tools

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

 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-06-2009
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
 
Reply With Quote
 
 
 
 
David Cournapeau
Guest
Posts: n/a
 
      08-06-2009
On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggisch<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-07-2009
David Cournapeau schrieb:
> On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggisch<(E-Mail Removed)> 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
 
Reply With Quote
 
David Cournapeau
Guest
Posts: n/a
 
      08-07-2009
On Fri, Aug 7, 2009 at 7:09 PM, Diez B. Roggisch<(E-Mail Removed)> wrote:

>
> Tried that, nothing changed


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

David
 
Reply With Quote
 
Stefan Behnel
Guest
Posts: n/a
 
      08-07-2009
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
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-10-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cython dynamic library problem Tommy Grav Python 3 09-18-2008 05:17 PM
Wrap Numpy with Cython? martin.nordstrom87@gmail.com Python 1 06-24-2008 08:09 PM
Cython code generation for Py3 complete Stefan Behnel Python 0 05-22-2008 08:10 AM
Types, Cython, program readability bearophileHUGS@lycos.com Python 13 03-29-2008 02:31 AM
HowTo Use Cython on a Windows XP Box? David Lees Python 5 09-01-2007 06:00 AM



Advertisments