简体   繁体   中英

python win32api fails after using pyinstaller

i have a problem which occurs after i use pyinstaller to form a executable. The piece of code use the function win32api.GetShortPathName to check if the file exists on a path with long filename, running the python file alone is no problem. After using pyinstaller the program fails in the same situation.

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.')

The error means in english: System cannot find path

You need to Enable Long Paths in Windows 10, Version 1607, and Later , Add the longPathAware element to the application manifest:

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

Or add " \\?\ " prefix to specify an extended-length path in the Unicode version of winapi, For example, " \\?\D:\very long path ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM