Search code examples
python-3.xpyinstallerhuggingface-transformers

ModuleNotFoundError: No module named 'h5py.utils'


So I am trying to run a chat-bot which I built using Tkinter and transformers as a standalone exe file [I am using Windows 10] but I would get a run time error every-time I execute it. Is there something I am doing wrong? I have been trying different commands for nearly 2 days.

Error generated below:

Traceback (most recent call last):
 RuntimeError: Failed to import transformers.modeling_tf_utils because of the following error (look up to see its traceback):
No module named 'h5py.utils'

Traceback (most recent call last): RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback): Failed to import transformers.modeling_tf_utils because of the following error (look up to see its traceback): No module named 'h5py.utils'

I have tried using the follow commands and added and removed additional hidden-imports but that didn't work:

pyinstaller -w  --icon=logo.ico --hidden-import="pkg_resources.py2_warn" --hidden-import="h5py.defs" --hidden-import="googleapiclient" --hidden-import="apiclient" --hidden-import=tensorflow --hidden-import=pytorch --hidden-import=transformers --hidden-import=tqdm --collect-data tensorflow --collect-data torch --copy-metadata tensorflow --copy-metadata torch --copy-metadata h5py --copy-metadata tqdm --copy-metadata regex --copy-metadata sacremoses --copy-metadata requests --copy-metadata packaging --copy-metadata filelock --copy-metadata numpy --copy-metadata tokenizers --copy-metadata importlib_metadata --hidden-import=“sklearn.utils._cython_blas” --hidden-import=“sklearn.neighbors.typedefs” --hidden-import=“sklearn.neighbors.quad_tree” --hidden-import=“sklearn.tree” --hidden-import=“sklearn.tree._utils” chatbot.py

Solution

  • I solved my problem. Here's what I did

    Before I start, do not use -onefile flag in your command.

    1. I ran the command " pyinstaller -w --icon=logo.ico --hidden-import="h5py.defs" --hidden-import="h5py.utils" --hidden-import="h5py.h5ac" --hidden-import="h5py._proxy" --hidden-import=tensorflow --hidden-import=transformers --hidden-import=tqdm --collect-data tensorflow --collect-data torch --copy-metadata tensorflow --copy-metadata torch --copy-metadata h5py --copy-metadata tqdm --copy-metadata regex --copy-metadata sacremoses --copy-metadata requests --copy-metadata packaging --copy-metadata filelock --copy-metadata numpy --copy-metadata tokenizers --copy-metadata importlib_metadata chatbot.py "

    2. Go to the \Lib\site-packages\certifi folder and copy the cacert.prem file.

    3. When you try to run the exe file from the generated dist folder, you will get an OSError about a missing TLS CA certificate bundle because it's pointing to a certifi folder that does not exist within the dist folder. From the generated dist folder, go to the main folder, Create a new folder and rename it "certifi" and paste the cacert.prem file in it.

    4. Re-run your exe file and it should work, it worked for me.