- 1 year ago
Enabling Windows long file path support in PyInstaller application
To enable Windows long file path support in a PyInstaller application, you can follow these steps:
Modify the PyInstaller bootloader: The PyInstaller bootloader,
pyi-bootstrap
, needs to be modified to enable long file path support. You can locate the bootloader file in your PyInstaller installation directory. By default, it is located atPyInstaller\bootloader\Windows-<arch>\pyi-bootstrap
.Open the bootloader file: Open the
pyi-bootstrap
file in a text editor.Add long path support code: In the
pyi-bootstrap
file, find the line that starts withsys.argv[0] =
. Below that line, add the following code:pythonimport ctypes
ctypes.windll.kernel32.SetDllDirectoryW(None)
This code sets the DLL directory to
None
, which enables long file path support.Save the modified bootloader file: Save the changes you made to the
pyi-bootstrap
file.Rebuild your PyInstaller application: Rebuild your PyInstaller application using the modified bootloader. Run the PyInstaller command to package your application as you normally would, but make sure to specify the modified bootloader using the
--bootloader
option. For example:bashpyinstaller --bootloader=path/to/modified/pyi-bootstrap your_script.spec
Replace
path/to/modified/pyi-bootstrap
with the path to the modified bootloader file you saved in step 4.
By modifying the PyInstaller bootloader and specifying the modified bootloader during the packaging process, you can enable Windows long file path support in your PyInstaller application. This allows your application to work with file paths that exceed the standard 260-character limit on Windows.
Note that modifying the PyInstaller bootloader is an advanced configuration and may have implications for the behavior and compatibility of your application. It's recommended to thoroughly test your application after making these changes to ensure that it works as expected in different scenarios and environments.