3

这是我的setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

wrapper = Extension(
    name="libwrapper",
    ...
)
setup(
    name="libwrapper",
    ext_modules=cythonize([wrapper])
)

当我运行python3 setup.py build_ext输出文件时调用libwrapper.cpython-36m-x86_64-linux-gnu.so,但我只想命名它libwrapper.so,我该怎么做?

4

1 回答 1

3

试试下面的代码。返回特定于平台的后缀,可以通过子类化和覆盖sysconfig.get_config_var('EXT_SUFFIX')从最终文件名中删除。build_extget_ext_filename

from distutils import sysconfig
from Cython.Distutils import build_ext
from distutils.core import setup
import os

class NoSuffixBuilder(build_ext):
    def get_ext_filename(self, ext_name):
        filename = super().get_ext_filename(ext_name)
        suffix = sysconfig.get_config_var('EXT_SUFFIX')
        ext = os.path.splitext(filename)[1]
        return filename.replace(suffix, "") + ext


setup(
    ....
    cmdclass={"build_ext": NoSuffixBuilder},
)

最终文件名将是test.so

于 2020-02-18T16:18:22.813 回答