2

My pyx depends upon a native library

How can I pyximport.install() it? The auto-build in pyxinstall doesn't know to link with the native library, so the build fails...

2 Answers 2

5

You can also specify build flags using a .pyxbld file.

For example, if you are trying to build yourmodule.pyx, simply place the following yourmodule.pyxbld file in the same directory as your pyx file:

def make_ext(modname, pyxfilename):
    from distutils.extension import Extension
    ext = Extension(name = modname,
        sources=[pyxfilename],
        extra_compile_args=['-I/path/to/my/custom/lib'],
        extra_link_args=['-Lpath/to/my/custom/lib', '-lcustomlib'])
    return ext

def make_setup_args():
    return dict(script_args=["--verbose"])
3

You can still export the correct LDFLAGS / CFLAGS before doing your pyximport.install() :

from os import environ
environ['CFLAGS'] = '-I/path/to/my/custom/lib'
environ['LDFLAGS'] = '-Lpath/to/my/custom/lib -lcustomlib'
import pyximport
pyximport.install()

However, pyximport should be used only in debug case. Prefer the setup.py method !

2
  • Not verified by Me, but wish I'd had this before I gave up on it all.
    – Will
    Commented Mar 2, 2011 at 13:14
  • Regards, setup.py, I'm rather inclined to think pyximport would be infinitely preferable to me than setup.py which is a pain to develop and debug code with
    – Will
    Commented Mar 2, 2011 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.