自定义Cython生成的.so文件的位置 [英] Customize location of .so file generated by Cython

查看:493
本文介绍了自定义Cython生成的.so文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有C库包装的Cython软件包。这是包的树结构

I have a Cython package with wrappers of a C library. This is the tree structure of the package

package/
       _api.pxd
       _wrap.pyx
       setup.py
       wrapper/
              __init__.py
              wrap.py

这样做

python setup.py build_ext --inplace

_wrap.so 文件放入顶级 package / 目录,通常在大多数情况下是必需的。但是,我的 wrap.py 需要 package / wrapper / <中的 _wrap.so / code>目录。我想知道 setup.py 是否可以自己在所需位置创建 .so 文件

puts the _wrap.so file in the top-level package/ directory which is normally required in most cases. However, my wrap.py needs the _wrap.so in the package/wrapper/ directory. I was wondering if there's a way in which setup.py could create the .so file in the desired place by itself without manually copying and pasting it in the location.

推荐答案

生成的 .so的输出文件夹文件可以指定为 setuptools.Extension 函数的第一个参数。

The output folder for the produced .so files can be specified as the first argument of setuptools.Extension function.

Cython扩展的示例,

Here is an example for Cython extensions,

from setuptools import setup, find_packages, Extension
from Cython.Distutils import build_ext

ext_modules=[
    Extension("package.wrapper.wrap",    # location of the resulting .so
             ["package/wrapper/wrap.pyx"],) ]


setup(name='package',
      packages=find_packages(),
      cmdclass = {'build_ext': build_ext},
      ext_modules = ext_modules,
     )

这篇关于自定义Cython生成的.so文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆