8

I am writing a python extension module that needs to link with a third-party DLL. How can I copy this DLL to the site-packages directory using distutils (i.e. in my setup.py file)?

Jason Sundram
  • 12,225
  • 19
  • 71
  • 86

1 Answers1

8

Put your DLL in the package_data argument of your setup() (see the Installing Package Data section of the distutils documentation for details).

If you need to put the DLL outside of the package directory , you can use the data_files option. For example to put it in the site-packages directory:

import distutils.sysconfig

setup(
    # [...]
    data_files = [(distutils.sysconfig.get_python_lib(), ["/path/to/the/DLL"])],
)
Luper Rouch
  • 9,304
  • 7
  • 42
  • 56
  • thanks. I want the DLL to get copied to the root level of site-packages, not into a package-specific subdirectory. Is there a way to do that using package_data? – Jason Sundram May 13 '10 at 16:04
  • The `data_files` option lets you put files anywhere you like, see the section 2.7 of the documentation I linked. – Luper Rouch May 13 '10 at 16:26
  • 2
    Another convenient piece of knowledge: Set the directory to an empty string to have the file installed in the package folder, e.g. `''` instead of `(distutils.sysconfig.get_python_lib()` – smiddy84 Jan 07 '19 at 10:16
  • How to provide the relative path to the .dll? – a11apurva Sep 21 '21 at 08:41