【问题标题】:How do you add a manifest to PyInstaller compiled EXE?如何将清单添加到 PyInstaller 编译的 EXE?
【发布时间】:2017-10-05 01:11:50
【问题描述】:

我正在尝试将此清单添加到我的 PyInstaller 编译的 EXE 中:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity name="TestApp" processorArchitecture="amd64" type="win32" version="1.0.0.0"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="amd64" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
    </dependentAssembly>
  </dependency>
  <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>

当我使用 PyInstaller 的 --manifest 选项时,它不会添加到 EXE 中或合并到生成的清单文件中。我什至找不到一行说它在构建过程中对清单做任何事情。然后我使用 MT.exe 嵌入清单而没有错误。此清单文件是对 PyInstaller 生成的文件的修改。我不得不删除兼容性部分,因为 MT.exe 说命名空间兼容性中没有兼容性选项......我添加了部分以声明应用程序具有 dpiAware。完成此操作后,我可以看到使用 ResourceHacker 添加的清单部分,但是当我运行该程序时,它说无法打开自我并且无法运行。当我使用 ResourceHacker 嵌入清单时,程序将加载但仍然大于打开 DPI 缩放的屏幕,就像它只是忽略了清单文件一样。我正在使用 python 3.5.1 和 kivy 1.9.1。

【问题讨论】:

    标签: python manifest pyinstaller


    【解决方案1】:

    我在使用 Pyinstaller 3.3 时遇到了同样的问题。 here 给出了解释,我调整了他们的答案,将其更新为 Pyinstaller 3.3,作为一种笨拙的解决方法。不幸的是,他们的解决方案需要编辑 Pyinstaller 源代码。

    在 Pyinstaller 中编辑 &lt;python install root&gt;\Lib\site-packages\PyInstaller\building\api.py 源文件,因此 assemble 方法的开头如下所示:

    def assemble(self):
        logger.info("Building EXE from %s", self.tocbasename)
        trash = []
        if os.path.exists(self.name):
            os.remove(self.name)
        if not os.path.exists(os.path.dirname(self.name)):
            os.makedirs(os.path.dirname(self.name))
        exe = self.exefiles[0][1]  # pathname of bootloader
        if not os.path.exists(exe):
            raise SystemExit(_MISSING_BOOTLOADER_ERRORMSG)
    
        # BEGINNING OF CHANGES
        if self.manifest_override != False:
            print "Overriding default manifest"
            tmpnm = tempfile.mktemp()
            shutil.copy2(exe, tmpnm)
            os.chmod(tmpnm, 0755)
            winmanifest.UpdateManifestResourcesFromXMLFile(tmpnm, self.manifest_override, names=[1], languages=[1033])
            exe = tmpnm
            trash.append(tmpnm)
        # END OF CHANGES
    
        if is_win and (self.icon or self.versrsrc or self.resources): 
    

    也在 api.py 中标记的部分

    # Available options for EXE in .spec files
    

    添加

    self.manifest_override = kwargs.get('manifest_override', False)
    

    最后在你的spec文件的EXE部分添加:

    manifest_override=[NAME AND PATH OF YOUR MANIFEST FILE IN QUOTES]
    

    【讨论】:

    • Python 3 和 Pyinstaller 4.3 更新(将相关行替换为以下内容):logger.info("Overriding default manifest") os.chmod(tmpnm, 0o755) 在规范文件中:manifest_override=NAME AND PATH OF YOUR MANIFEST FILE IN QUOTES(不带括号)
    猜你喜欢
    • 2014-09-06
    • 2016-06-07
    • 2021-01-11
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 2018-11-11
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多