[Python] migrating from distutils to setup tools

Discussão em 'Python' iniciado por Stack, Novembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I am migrating a large library of python cpp extensions form swig+distutils to swig+setuptols. I am using swig cpp example as the illustration. The original setup.py file:

    from distutils.core import setup, Extension
    from distutils.command.build_ext import build_ext

    example_module = Extension(
    name='_example',
    sources=['example.i', 'example.cpp'],
    swig_opts=['-python', '-py3', '-c++', '-cppext', 'cpp']
    )

    setup(
    name='example',
    version='1.0',
    ext_modules=[example_module],
    )


    And I building it as

    /usr/bin/python3 setup.py build_ext --swig=${SWIG}
    /usr/bin/python3 setup.py install --prefix ${PREFIX} --install-lib ${LIBDIR} --no-compile --skip-build


    I replaced distutils.core -> setuptools and distutils.command -> setuptools.command in my setup.py file. I added PYTHONPATH=${LIBDIR} to my install command.

    I got everything built. And I can run my example. However, instead of .so file in the library _example.cpython-38-x86_64-linux-gnu.so, I got an 'egg' file, site.py and easy-install.pth:

    easy-install.pth
    example-1.0-py3.8-linux-x86_64.egg
    site.py


    What is next? Should I simply use .egg files instead of .so files? I tried to use .egg files for a more complicated example and it did not work.

    I unzipped .egg file, it worked for both the simple example and for more a complicated one. But I feel that simply unzipping these files as a part of the build process is not the right thing to do.

    Continue reading...

Compartilhe esta Página