PyInstaller Hooks Contrib
PyInstaller Hooks Contrib is a collection of community-maintained hooks that extend PyInstaller's ability to bundle complex Python applications. These hooks handle the specific packaging requirements of various third-party libraries, ensuring they work correctly when frozen into a standalone executable. The current version is 2026.4, with releases typically following a monthly cadence.
Warnings
- gotcha Many popular third-party libraries (e.g., PyQt, Kivy, matplotlib, scipy) will fail to build or run correctly when bundled with PyInstaller if `pyinstaller-hooks-contrib` is not installed, as it provides essential community-maintained hooks for these packages.
- gotcha While not strictly tied, ensure that your `pyinstaller-hooks-contrib` version is relatively up-to-date with your `PyInstaller` version. Newer PyInstaller versions might expect newer hook definitions, and older `contrib` versions could lead to build issues.
- gotcha Hooks for a specific library within `pyinstaller-hooks-contrib` might occasionally lag behind very recent versions of that third-party library. This can lead to bundling issues even with the contrib package installed.
Install
-
pip install pyinstaller pyinstaller-hooks-contrib
Imports
- Not Applicable
This library provides hooks that PyInstaller automatically discovers and uses during the build process. Direct imports of `pyinstaller-hooks-contrib` in user application code are not performed.
Quickstart
import matplotlib.pyplot as plt
import numpy as np
def create_plot():
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title("Simple Sine Wave")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
if __name__ == "__main__":
create_plot()
print("Matplotlib imported successfully (for PyInstaller testing).")
# To use:
# 1. Save the above code as app.py
# 2. Ensure pyinstaller and pyinstaller-hooks-contrib are installed:
# pip install pyinstaller pyinstaller-hooks-contrib
# 3. Run PyInstaller:
# pyinstaller app.py
# PyInstaller will automatically use the hooks from pyinstaller-hooks-contrib to correctly bundle matplotlib and numpy.