开发者

Python: pyximporting a pyx that depends on a native library

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 libr开发者_开发知识库ary, so the build fails...


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"])


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 !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜