Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

python - How do you add a manifest to PyInstaller compiled EXE?

I am trying to add this manifest to my PyInstaller compiled 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>

When I use PyInstaller's --manifest option it isn't added to the EXE or combined in the generated manifest file. I couldn't even find a line saying it was doing anything with the manifest during build. I then used MT.exe to embed the manifest with no errors. This manifest file is a modification of the one generated by PyInstaller. I had to remove the compatibility section because MT.exe said there was no compatibility option in the namespace compatibility... I added the part in to declare the app has dpiAware. After I do this I can see the manifest section added in with ResourceHacker but when I go to run the program it says that can't open self and does not run. When I embed the manifest using ResourceHacker the program will load but is still larger then the screen with DPI scaling turned on like it just ignored the manifest file. I am using python 3.5.1 and kivy 1.9.1.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had this same problem, using Pyinstaller 3.3. An explanation is given here and I adapted their answer, updating it for Pyinstaller 3.3, as a clumsy workaround. Their solution requires editing the Pyinstaller source code, unfortunately.

Edit the <python install root>Libsite-packagesPyInstalleruildingapi.py source file in Pyinstaller, so the beginning of the assemble method looks like this:

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): 

also in api.py in the section labeled

# Available options for EXE in .spec files

add

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

Finally in your spec file in the EXE section add:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...