python win32api在使用pyinstaller后失败



我在使用pyinstaller形成可执行文件后遇到了一个问题。这段代码使用函数win32api.GetShortPathName来检查文件是否存在于文件名较长的路径上,单独运行python文件没有问题。使用pyinstaller后,程序在同样的情况下失败。

Traceback (most recent call last):
File "pycopy.py", line 32, in cp
pywintypes.error: (3, 'GetShortPathNameW', 'Das System kann den angegebenen Pfad nicht finden.')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:program filespython37libthreading.py", line 926, in _bootstrap_inner
self.run()
File "c:program filespython37libthreading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "pycopy.py", line 131, in download
File "pycopy.py", line 83, in copyit
File "pycopy.py", line 36, in cp
pywintypes.error: (3, 'GetShortPathNameW', 'Das System kann den angegebenen Pfad nicht finden.')

错误的英文意思是:系统找不到路径

您需要在Windows 10 1607及更高版本中启用长路径,将longPathAware元素添加到应用程序清单:

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>

或者加上";CCD_ 2";前缀,以指定winapi的Unicode版本中的扩展长度路径。例如;\?D:very long path";。

最新更新