Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

PyInstaller Hidden Imports: What They Are and How to Fix Them

PyInstaller can miss modules chosen at runtime because their names are not visible during source analysis. Learn how hidden imports differ from missing paths, data files, and binaries.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PyInstaller’s Analysis phase can usually find modules named in ordinary import statements. A hidden import is a module the application needs but that analysis cannot see in the source; if the program asks for it at runtime, the frozen application may fail because the module was not bundled. Specify a known module with --hidden-import, use a package hook, or collect a broader set of submodules when the package requires it.

What PyInstaller means by a hidden import

PyInstaller analyzes your program to identify Python modules to include in the bundle. Its command-line documentation describes --hidden-import as a way to “Name an import not visible in the code of the script(s).” The option can be used more than once. PyInstaller: Using PyInstaller

As an Amazon Associate I earn from qualifying purchases.

The word “hidden” describes what the analysis can see, not a special kind of Python module. If your application needs a module but PyInstaller cannot identify it from the analyzed code or applicable hooks, you may need to tell the build to include it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why runtime-selected imports can go missing

An ordinary statement such as import package.module gives analysis a visible reference to follow. A program can instead choose a module at runtime—for example, by assembling its name from configuration and passing that name to importlib.import_module, using __import__, or selecting a plugin. The eventual target may not appear as a literal import in the analyzed source, so PyInstaller may not know to bundle it. The exact outcome depends on the code and any relevant hooks.

That is why dynamic imports are a common cause of missing modules in frozen applications, but it is not accurate to say that only dynamic imports break. PyInstaller notes that most packages use normal import methods and are located without difficulty, while unusual import mechanisms or runtime changes can make collection unreliable. A missing data file, shared library, or package metadata is a different problem from a hidden Python-module import. PyInstaller: Understanding PyInstaller Hooks

Choose a fix that matches what is missing

Remedy Use it when Scope
--hidden-import=package.module You know the specific Python module the application needs, but analysis does not find it. One named module; repeat the option for additional modules.
Package hook with hiddenimports A package has import behavior that needs a reusable, package-specific declaration. Modules declared by the hook when Analysis encounters the hooked package.
--collect-submodules package The application needs a known package’s submodules rather than just one target. Submodules of the named package.
--collect-all package The application needs a broader package collection, including non-code resources. Submodules, data files, and binaries for the named package.
--paths DIR The module exists in the build environment but its directory is not on the analysis search path. Adds a directory to the import search path; it does not declare a hidden import.

The command-line options and their collection scopes are documented in PyInstaller: Using PyInstaller. Hook behavior, including hidden imports and collection of other resources, is described in PyInstaller: Understanding PyInstaller Hooks.

How to add a hidden import

Declare one known module in the build command

Add the exact importable module name to the PyInstaller command:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pyinstaller --hidden-import=package.module your_script.py

Replace package.module with the module your application actually requests. Add another --hidden-import option for each additional known module. This is the narrowest fix when the missing target is clear.

Put package-specific knowledge in a hook

A hook can declare hidden imports in a hiddenimports list, for example:

hiddenimports = ["package.module"]

PyInstaller applies a hook when Analysis encounters the package it is associated with. This is useful when the package’s indirect imports should be handled consistently in builds that use the hook. The official hook documentation illustrates this pattern with an indirectly registered module. PyInstaller: Understanding PyInstaller Hooks

Collect a package’s wider contents only when needed

Use --collect-submodules package when the application needs a package’s submodules. Use --collect-all package only if it also needs that package’s data files and binaries. These broader options can include more than a single hidden import, so match the collection scope to the dependency rather than expanding it by default. PyInstaller: Using PyInstaller

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a hidden import is not the right fix

  • The module is not discoverable during the build: Check whether it is installed in the build environment and whether its directory is searched. --paths DIR adds an import search directory; it addresses analysis discoverability rather than a runtime-selected import target.
  • The failure names a file or package resource: Investigate data-file collection, not just Python imports.
  • The failure names a shared library: Check binary collection and the dependency’s hook behavior.
  • The failure involves package metadata: Use the relevant metadata collection mechanism rather than assuming a hidden module is missing.

PyInstaller hooks can manage data files, binaries, and package metadata as well as hidden imports. These resource-collection issues are related to bundling but are distinct from a Python module that analysis cannot see. PyInstaller: Understanding PyInstaller Hooks

Diagnose the failed build before widening collection

Start with the runtime error and build output. A missing-module error points toward an import or analysis-search issue; a missing file, shared library, or metadata lookup points toward a different collection requirement. Then identify the exact module or resource the application requests and choose the narrowest matching remedy. The official documentation explains the general mechanics, but identifying why a particular build fails depends on its dependency, Python and PyInstaller versions, build warnings or logs, and import code.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.