简体   繁体   English

在py2exe构建中包含PYD / DLL

[英]Including PYDs/DLLs in py2exe builds

One of the modules for my app uses functions from a .pyd file. 我的应用程序的一个模块使用.pyd文件中的函数。 There's an option to exclude dlls (exclude_dlls) but is there one for including them? 有一个选项可以排除dlls(exclude_dlls),但有一个包含它们吗? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). 尽管复制了其余的文件(.py),构建过程似乎并没有复制模块中的.pyd。 I also need to include a .dll. 我还需要包含一个.dll。 How do I get py2exe to include both .pyd and .dll files? 如何让py2exe包含.pyd和.dll文件?

.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. .pyd和.DLL在这里是不同的,因为.pyd应该由modulefinder自动找到并且包含(只要你有适当的“import”语句),而不需要做任何事情。 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. 如果错过了一个,你会做同样的事情,好像错过.py文件(它们都只是模块):使用py2exe选项的“include”选项。

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. Modulefinder不一定会找到.DLLs的依赖项(py2exe可以检测到一些),因此您可能需要使用'data_files'选项显式包含这些依赖项。

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: 例如,你要包含两个.DLL('foo.dll'和'bar.dll'),以及三个.pyd('module1.pyd','module2.pyd'和'module3.pyd')到包括:

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

If they're not being automatically detected, try manually copying them into py2exe's temporary build directory. 如果没有自动检测到它们,请尝试手动将它们复制到py2exe的临时构建目录中。 They will be included in the final executable. 它们将包含在最终的可执行文件中。

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. 等...当然,修改以满足您的需求。

Maybe you could use the data_files option to setup(): 也许你可以使用data_files选项来设置():

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: data_files应该是元组列表,其中每个元组包含:

  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. 这不会把文件放到library.zip中,这应该不是dll的问题,但我不知道pyd文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM