luminousmen / luminousmen.com

2 stars 0 forks source link

https://luminousmen.com/post/resolve-cython-and-numpy-dependencies #2

Closed utterances-bot closed 3 weeks ago

utterances-bot commented 4 years ago

Resolve cython and numpy dependencies on setup step

Describing how to resolve cython and numpy dependencies on setup step.

https://luminousmen.com/post/resolve-cython-and-numpy-dependencies

lasofivec commented 4 years ago

I'm curious if you purposely left out the numpy part in the solution? include_dirs=[numpy.get_include()]

luminousmen commented 4 years ago

@lasofivec, thanks for your feedback!

No, that was not intentional - I change the post.

lasofivec commented 4 years ago

In that case, from my experience the wrapping solution won't work. Or at least I didn't find a way of wrapping the numpy.get_include() in a clever way. Seems to me like using a newer version of setuptools is the only working solution (or explicit installing it, like in your last code snippet)

ghost commented 4 years ago

not a super clever way, but a way :

class WhateverExt(Extension): def init(self, *args, *kwargs): self._include = [] super().init(args, **kwargs)

@property
def include_dirs(self):
    # defer import of numpy
    import numpy
    return self._include + [numpy.get_include()]

@include_dirs.setter
def include_dirs(self, dirs):
    self._include = dirs

ext_modules = [ WhateverExt( name="stuff.stuff", sources=["src/stuff/stuff.pyx"], )]

lasofivec commented 4 years ago

@jacboi What version of setuptools did you use ?