我在使用PyInstaller将一个脚本构建成可执行文件时遇到了一个问题,这个脚本在作为Python脚本运行时工作正常,但作为PyInstaller应用程序运行时,当遇到路径超过260个字符的文件时就会失败。脚本作为Python脚本运行时工作正常,但作为PyInstaller应用程序运行时,当遇到一个路径超过260个字符的文件时,就会失败。
我知道这是由于一个 Windows的限制 和支持更长的路径必须 选入 在注册表中和使用应用程序清单都可以使 longPathAware
设置。顺便说一下,这在 Python 中工作的原因是因为 在Python 3.6中,开发者启用了这个设置 对于 python.exe
和 pythonw.exe
.
到目前为止,我已经完成了所有这些工作,如果我把下面的清单文件放在构建的PyInstaller应用程序旁边,它确实可以工作(使用 --onefile
模式)。)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>
然而,为了让应用程序对最终用户来说是自足的和可移植的,我试图避免使用外部清单文件,而是让PyInstaller将这个自定义清单嵌入到可执行文件中。
这个 --manifest
选择权 据称是这样做的 -- 至少从PyInstaller 3.5开始,根据 变革日志 和 PR #3746:
但是当指定了自定义的清单文件时,似乎被忽略了,因为在外部清单文件没有到位的情况下,应用程序在长路径上继续失败,检查捆绑的清单文件在 --onedir
模式,只是看起来像是忽略了自定义的模式,而创建了这个模式。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependency>
<dependentAssembly>
<assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
我是不是做错了什么或者理解错了什么?是否在 --manifest
选项没有做到我想的那样?这是一个错误吗?
这个答案 描述了修改PyInstaller源码以覆盖嵌入式清单的创建。这还有必要吗?
我还在GitHub上看到一个项目,似乎也有同样的问题;该项目的作者是 此公关 状态。
请注意,PyInstaller并不理解以下内容
longPathAware
设置,并将其从清单中剥离出来。
我不知道这是否属实,但我认为这确实是一个错误。
我使用PyInstaller 3.6、Python 3.7.2和Windows 10 1809版本。