如何将清单添加到PyInstaller编译的EXE? [英] How do you add a manifest to PyInstaller compiled EXE?
问题描述
我正在尝试将此清单添加到我的PyInstaller编译的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>
当我使用PyInstaller的--manifest选项时,它不会添加到EXE或合并在生成的清单文件中.我什至找不到一条线说它在构建过程中对清单做了任何事情.然后,我使用MT.exe嵌入清单,没有错误.此清单文件是对PyInstaller生成的清单文件的修改.我必须删除兼容性部分,因为MT.exe表示名称空间兼容性中没有兼容性选项...我在其中添加了一部分,以声明应用程序具有dpiAware.完成此操作后,我可以看到ResourceHacker中添加了清单部分,但是当我去运行该程序时,它说无法打开自我并且无法运行.当我使用ResourceHacker嵌入清单时,程序将加载,但仍然更大,然后打开DPI缩放的屏幕,就像它只是忽略了清单文件一样.我正在使用python 3.5.1和kivy 1.9.1.
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.
推荐答案
我在使用Pyinstaller 3.3时遇到了同样的问题.在此处给出了解释,我进行了修改他们的答案,将其更新为Pyinstaller 3.3,这是一个笨拙的解决方法.不幸的是,他们的解决方案需要编辑Pyinstaller源代码.
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.
在Pyinstaller中编辑<python install root>\Lib\site-packages\PyInstaller\building\api.py
源文件,所以assemble方法的开始看起来像这样:
Edit the <python install root>\Lib\site-packages\PyInstaller\building\api.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):
同样在api.py中标记为
also in api.py in the section labeled
# Available options for EXE in .spec files
添加
self.manifest_override = kwargs.get('manifest_override', False)
最后在EXE部分的规范文件中添加:
Finally in your spec file in the EXE section add:
manifest_override=[NAME AND PATH OF YOUR MANIFEST FILE IN QUOTES]
这篇关于如何将清单添加到PyInstaller编译的EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!