python win32api在使用pyinstaller后失败

2024-05-20 13:17:28 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用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 files\python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "c:\program files\python37\lib\threading.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.')

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


Tags: 文件inpyself路径mostlinecall
1条回答
网友
1楼 · 发布于 2024-05-20 13:17:28

您需要Enable Long Paths in Windows 10, Version 1607, and Later,将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>

或者添加“\\?\”前缀以指定winapi的Unicode版本中的扩展长度路径,例如“\\?\D:\very long path

相关问题 更多 >