Python: pyximporting pyx which depends on native library

My pyx depends on the native library

How can I get pyximport.install()

it? The auto build in pyxinstall doesn't know to link to the native library, so the build doesn't work ...

+2


a source to share


2 answers


You can export the correct LDFLAGS / CFLAGS before doing 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 only be used for debugging purposes. Prefer the setup.py method!

+2


a source


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

For example, if you are trying to create yourmodule.pyx , just place the following yourmodule.pyxbld 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


a source







All Articles