Including PYDs/DLLs in py2exe builds
Asked Answered
D

4

10

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?

Dubbin answered 21/10, 2008 at 4:40 Comment(0)
L
12

.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"}}
     )
Limber answered 22/10, 2008 at 2:27 Comment(3)
In the current version of py2exe, data_files should look like so: data_files = [ (DIR, [FILE, FILE, FILE]), ... ]Seth
When I do this I need to use "includes" rather than "include" or py2exe complains.Thiazine
I have the same problem with finding pyd files and I have already tried including the missing resource but py2exe still couldn't find it.Hexachord
K
2

If they're not being automatically detected, try manually copying them into py2exe's temporary build directory. They will be included in the final executable.

Kathlyn answered 21/10, 2008 at 5:8 Comment(1)
Yes, but ideally that should be part of the setup.py script or put in my batch script for creating the executable.Dubbin
L
2

You can modify the setup script to copy the files explicitly:

script = "PyInvaders.py"        #name of starting .PY
project_name = os.path.splitext(os.path.split(script)[1])[0]
setup(name=project_name, scripts=[script]) #this installs the program

#also need to hand copy the extra files here
def installfile(name):
    dst = os.path.join('dist', project_name)
    print 'copying', name, '->', dst
    if os.path.isdir(name):
    dst = os.path.join(dst, name)
    if os.path.isdir(dst):
        shutil.rmtree(dst)
    shutil.copytree(name, dst)
    elif os.path.isfile(name):
    shutil.copy(name, dst)
    else:
    print 'Warning, %s not found' % name

pygamedir = os.path.split(pygame.base.__file__)[0]
installfile(os.path.join(pygamedir, pygame.font.get_default_font()))
installfile(os.path.join(pygamedir, 'pygame_icon.bmp'))
for data in extra_data:
    installfile(data)

etc... modify to suit your needs, of course.

Lezley answered 21/10, 2008 at 5:51 Comment(0)
M
2

Maybe you could use the data_files option to setup():

import glob
setup(name='MyApp',
      # other options,
      data_files=[('.', glob.glob('*.dll')),
                  ('.', glob.glob('*.pyd'))],
     )

data_files should be a list of tuples, where each tuple contains:

  1. The target directory.
  2. A list of files to copy.

This won't put the files into library.zip, which shouldn't be a problem for dlls, but I don't know about pyd files.

Malherbe answered 22/10, 2008 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.