在 py2exe 构建中包含 PYD/DLL

发布于 2024-07-08 07:52:52 字数 169 浏览 8 评论 0原文

我的应用程序的模块之一使用 .pyd 文件中的函数。 有一个选项可以排除 dll (exclude_dlls),但是是否有一个选项可以包含它们? 尽管复制了其余文件(.py),但构建过程似乎并未复制我的模块中的 .pyd。 我还需要包含一个 .dll。 如何让 py2exe 同时包含 .pyd 和 .dll 文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小ぇ时光︴ 2024-07-15 07:52:53

也许您可以使用 setup() 的 data_files 选项:

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

data_files 应该是元组列表,其中每个元组包含:

  1. 目标目录。
  2. 要复制的文件列表。

这不会将文件放入library.zip中,这对于dll来说不应该是问题,但我不知道pyd文件。

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.

晨光如昨 2024-07-15 07:52:52

.pyd 和 .DLL 在这里有所不同,因为 .pyd 应该由 modulefinder 自动找到并包含在内(只要您有适当的“导入”语句),而不需要执行任何操作。 如果丢失了一个,您将执行与丢失 .py 文件相同的操作(它们都只是模块):使用 py2exe 选项的“include”选项。

Modulefinder 不一定会找到 .DLL 的依赖项(py2exe 可以检测到一些),因此您可能需要使用“data_files”选项显式包含这些依赖项。

例如,您有两个 .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"}}
     )

.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"}}
     )
潦草背影 2024-07-15 07:52:52

如果没有自动检测到它们,请尝试手动将它们复制到 py2exe 的临时构建目录中。 它们将包含在最终的可执行文件中。

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.

绿萝 2024-07-15 07:52:52

您可以修改安装脚本以显式复制文件:

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)

等等……当然,可以修改以满足您的需要。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文