1

Background:

I've used SWIG to develop a Python wrapper for a C/C++ library.

Now I need to use setuptools to package the project for distribution. The package needs to include the SWIG generated C extension and all DLL dependencies. My project directory looks like the following:

project_directory/
  |
  --- foo_mod/
  |      |
  |      --- __init__.py
  |
  --- libs/
  |    |
  |    --- lib_a.dll
  |    --- lib_b.dll
  |
  --- core.py (generated by SWIG)
  --- core_wrap.cxx (generated by SWIG)
  --- core_wrap.h
  --- setup.py

What I have tried:

from setuptools import setup, find_packages, Extension

application_module = Extension(
    '_core',
)

setup(
    name='foo_mod',
    version='0.1',
    author="My Name",
    email="my.name@company.com",
    description="""Simple example""",
    ext_modules=[application_module],
    packages=find_packages(),
    package_data={
        "" : ['libs/*.dll']
    },
    py_modules=['core'],
    python_requires='>=3.6')

Command to build the extension:

PS > python setup.py build_ext --build-lib .\foo_mod

Following this command, the python extension _core.pyd is written to foo_mod\.

Command to build the package:

PS > python setup.py sdist bdist_wheel

Problem: The _core.pyd extension and libs are not being included into the wheel.

Question: How do I properly include the library dependencies into the package?

rgmann
  • 31
  • 2
  • 1
    1. AFAIK `package_data` can't include files for an empty string, it should be a package name that is included in the distribution (=contained in the `packages` list). 2. The `_core.pyd` is probably not included because you have named the extension `_core`, but are placing the lib into `foo_mod` - in that case, the extension name should be `foo_mod._core`. I may be wrong though - complete the question to a [mcve] to be reproducible locally. – hoefling Mar 02 '20 at 16:28
  • @hoefling 1) From the [documentation](https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files), the empty string is used to apply the associated rule to all packages found by `find_packages`. 2) It appears I was mistaken. The .pyd is being detected and included by `setuptools`. The DLLs are the only ones I can't seem to get it to find and include. – rgmann Mar 03 '20 at 05:36
  • Yes, I see. I guess the error is then that your `libs` directory doesn't belong to any package, move it inside the `foo_mod` directory to fix. – hoefling Mar 03 '20 at 08:48

0 Answers0