Including PYDs/DLLs in py2exe builds

TheObserver picture TheObserver · Oct 21, 2008 · Viewed 14.5k times · Source

One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to include both .pyd and .dll files?

Answer

Tony Meyer picture Tony Meyer · Oct 22, 2008

.pyd's and .DLL's are different here, in that a .pyd ought to be automatically found by modulefinder and so included (as long as you have the appropriate "import" statement) without needing to do anything. If one is missed, you do the same thing as if a .py file was missed (they're both just modules): use the "include" option for the py2exe options.

Modulefinder will not necessarily find dependencies on .DLLs (py2exe can detect some), so you may need to explicitly include these, with the 'data_files' option.

For example, where you had two .DLL's ('foo.dll' and 'bar.dll') to include, and three .pyd's ('module1.pyd', 'module2.pyd', and 'module3.pyd') to include:

setup(name='App',
      # other options,
      data_files=[('.', 'foo.dll'), ('.', 'bar.dll')],
      options = {"py2exe" : {"includes" : "module1,module2,module3"}}
     )