You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyInstaller生成exe报错‘failed to execute script’求助

Troubleshooting "Failed to execute script {name}" with PyInstaller for your simulator.pyw

Let's break down the possible issues and fixes based on your spec file and problem description:

1. First, get the actual error message (most critical step)

The generic "Failed to execute script" error doesn't give us enough detail to diagnose the problem. To see the real traceback:

  • Modify your EXE block in the spec file to set console=True:
    exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='simulator', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=True , icon='bin\\ui\\icon.ico')
    
  • Rebuild the exe with pyinstaller simulator.spec
  • Run the generated exe again—this time a console window will pop up showing the exact error (like a missing module, file not found, or syntax issue). This is the fastest way to pinpoint the root cause.

Windows paths require proper handling, and PyInstaller is strict about path formatting:

  • Pathex: Your pathex=['C:\Simulator'] uses an unescaped backslash, which can cause unexpected parsing. Change it to a raw string or use forward slashes:
    pathex=[r'C:\Simulator']  # Raw string avoids escape issues
    # OR
    pathex=['C:/Simulator']
    
  • Icon path: The same escape problem applies to 'bin\ui\icon.ico'—escape the backslashes or use forward slashes:
    icon='bin\\ui\\icon.ico'
    # OR
    icon='bin/ui/icon.ico'
    
  • Datas collection: The ** wildcard might not work as expected in PyInstaller's datas configuration. Since you're working with .kv files (likely a Kivy app), try specifying the exact subdirectory instead of using recursive wildcards:
    datas=[('bin/ui/*.kv', 'bin/ui'), ('bin/ui/*.xml', 'bin/ui')]
    
    Also, double-check that your simulator.pyw loads these files using relative paths that match the structure in the dist/simulator folder after packaging.

3. Check for missing hidden imports

PyInstaller often fails to auto-detect dependencies for frameworks like Kivy. Update your hiddenimports list to include modules your app relies on. For a basic Kivy app, this might look like:

hiddenimports=['kivy.lang.builder', 'kivy.uix.boxlayout', 'kivy.uix.button']  # Add modules your app uses

You can also run an initial build with pyinstaller --hidden-import=MODULE_NAME simulator.pyw to test missing imports, then add them to your spec file permanently.

4. Verify file permissions and location

  • Try running the exe from a non-restricted directory (like your Desktop) instead of Program Files or other protected folders—Windows permissions can block apps from accessing required files.
  • After packaging, check if all .kv and .xml files are present in dist/simulator/bin/ui. If they're missing, your datas configuration is incorrect.

5. Disable UPX temporarily

UPX compression can sometimes break certain binaries or scripts. Try rebuilding with upx=False in both EXE and COLLECT blocks to rule out this issue:

exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='simulator', debug=False, bootloader_ignore_signals=False, strip=False, upx=False, console=True , icon='bin\\ui\\icon.ico')
coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=False, upx_exclude=[], name='simulator')

Once you get the actual error from the console, you'll be able to narrow down the problem even further!

内容的提问来源于stack exchange,提问作者Treex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:46:32