close

How to properly create a pyinstaller hook, or maybe hidden import?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to properly create a pyinstaller hook, or maybe hidden import in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to properly create a pyinstaller hook, or maybe hidden import?

  1. How to properly create a pyinstaller hook, or maybe hidden import?

    If you add a hook-data.py file which contains a line hiddenimports = ['_proxy', 'utils', 'defs'], PyInstaller will check it to find additional imports when it sees import data.

  2. properly create a pyinstaller hook, or maybe hidden import

    If you add a hook-data.py file which contains a line hiddenimports = ['_proxy', 'utils', 'defs'], PyInstaller will check it to find additional imports when it sees import data.

Method 1

Hooks are files that specify additional actions when PyInstaller finds import statements.

If you add a hook-data.py file which contains a line hiddenimports = ['_proxy', 'utils', 'defs'], PyInstaller will check it to find additional imports when it sees import data.

You have to specify the path to the hook directory via --additional-hooks-dir (this is useful if you don’t want to mix your source code with compile-only files, and instead keep them in a separate directory).

The simpler solution is to use --hidden-import=modulename along with the PyInstaller script. It will add modulename as import statement silently.

Hooks are better if you want to specify which import needs what additional modules. --hidden-import is simpler as a one-shot or for debugging.

Method 2

Use Auto-py-to-exe to add hindden libraries. In additional files add Rasterio folder (C:/users/Admin/anaconda3/envs/name/Lib/site-packages/rasterio) and then convert to exe.

It worked for me. if it says some other libraries are missing then add folder of that library too.

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read