这是我的设置.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
,我该如何做到这一点?
尝试以下代码。sysconfig.get_config_var('EXT_SUFFIX')
返回特定于平台的后缀,该后缀可以通过子类化build_ext
和重写get_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