You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

PyInstaller打包启动屏程序生成超大文件夹问题求助

Hey there! Let's fix that absurdly large 630MB PyInstaller build for your splash screen app—way too bloated for such a simple tool. Here are practical, tested steps to slim it down drastically:

1. Optimize Your PyInstaller Build Commands First

Start with better parameters to avoid packing junk in the first place:

  • Use --onefile (if you can tolerate a tiny startup delay)
    This bundles everything into a single compressed executable, which is almost always smaller than a folder build. Add --windowed to skip the console window (perfect for a splash screen):
    pyinstaller --onefile --windowed your_splash_script.py
    
  • Exclude unused dependencies explicitly
    If you're using a GUI framework like PyQt/PySide, you're probably packing tons of unused modules (like QtWebEngine, QtMultimedia, etc.). Exclude them with --exclude-module:
    pyinstaller --windowed --exclude-module PyQt5.QtWebEngine --exclude-module PyQt5.QtMultimedia your_splash_script.py
    
  • Enable UPX compression
    UPX shrinks binary files significantly. Install UPX first (it's free), then add the --upx flag (or --upx-dir /path/to/upx if it's not in your PATH):
    pyinstaller --windowed --upx your_splash_script.py
    
  • Clean up cached files
    PyInstaller caches builds to speed things up, but old cache can add bloat. Use --clean to start fresh:
    pyinstaller --clean --windowed your_splash_script.py
    
2. Post-Build Cleanup (For Your Existing dist Folder)

Since you already have the dist directory, here's how to trim it manually:

  • Delete the entire share folder
    You noticed this is the biggest culprit—theme files are completely unnecessary for a standalone splash screen. Just delete the share directory inside your dist folder; your app won't miss it.
  • Prune unused dynamic libraries
    Most of the .so (Linux) or .dll (Windows) files aren't actually needed. To find which ones your app depends on:
    • On Linux: Run ldd dist/your_app_executable | grep -o '/.*\.so' to get a list of required libraries. Delete any .so files in dist that aren't on this list.
    • On Windows: Use Dependency Walker (a free tool) to open your .exe and see which DLLs it actually uses. Delete all others.
  • Strip debug symbols
    Remove unnecessary debug data from your executable and libraries:
    • Linux: Run strip dist/your_app_executable and strip dist/*.so
    • Windows: Use the strip.exe tool (from MinGW or Visual Studio) on your .exe and DLLs.
3. Cut Dependencies at the Source

The best way to reduce size is to use fewer dependencies in the first place:

  • Use a minimal virtual environment
    Create a fresh venv, install only what your splash screen needs (e.g., just pyqt5 instead of the full PyQt5 suite, or even just Python's built-in tkinter if your splash screen is simple). No extra packages = no extra bloat.
  • Switch to a lighter GUI library
    If your splash screen doesn't need advanced features, ditch heavy frameworks like PyQt. Tkinter is built into Python, so it adds almost nothing to your build size. PySimpleGUI (a lightweight wrapper for tkinter) is also a great option if you want nicer visuals without the bloat.
  • Clean up your imports
    Don't import entire modules if you only need one class. Instead of import PyQt5.QtWidgets, use from PyQt5.QtWidgets import QSplashScreen—this tells PyInstaller to skip packing unused parts of the library.
4. Advanced: Tweak the PyInstaller Spec File

For full control, generate and edit a spec file:

  1. Generate the spec file with:
    pyinstaller --windowed your_splash_script.py
    
  2. Open the generated your_splash_script.spec file in a text editor.
  3. Add more modules to the excludes list (e.g., excludes=['PyQt5.QtWebEngine', 'PyQt5.QtMultimedia']).
  4. Set strip=True to automatically remove debug symbols during the build.
  5. Only include necessary resource files in the datas list—don't let PyInstaller pack extra stuff.

With these steps, you should be able to get your splash screen app down to a much more reasonable size—often under 50MB even with Qt. Give them a shot and let me know if you hit any snags!

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

火山引擎 最新活动