2

I was trying to make a .py to .exe file using pyinstaller. After building the exe file, when I tried to run the .exe file through cmd, then it shows this error bellow.

D:\Ne folder\New folder\GuiExe>GuiExe.exe
Using TensorFlow backend.
Traceback (most recent call last):
  File "GuiExe.py", line 4, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\__init__.py", line 3, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\utils\__init__.py", line 6, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\backend\__init__.py", line 1, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\backend\load_backend.py", line 90, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow\__init__.py", line 101, in <module>
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
  File "lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
  File "lib\site-packages\tensorflow\__init__.py", line 44, in _load
  File "importlib\__init__.py", line 126, in import_module
  File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
ImportError: cannot import name 'pywrap_tensorflow'
[1764] Failed to execute script GuiExe

P.s. I also tied --hidden-import pywrap_tensorflow and --paths where pywrap_tensorflow.py file situated.

My PY to EXE command was

pyinstaller --paths C:/Users/Manash/tesorflow/Lib/site-packages/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py --hidden-import pkg_resources.py2_warn --hidden-import pywrap_tensorflow --add-data "C:/Ne folder/train_with_vali_test_model_6_111(GLOVES)_soreo-ou_test.pckle";. GuiExe.py

My python version# 3.5.4 Tensorflow version# 2.1.0 keras version# 2.3.1

Please, help me, and tell me should I give more information, or Which ones information should I provide. To get a solution. Thanks in advance.

  • You can try the solution stated [here](https://stackoverflow.com/questions/60384288/pyinstaller-modulenotfounderror). – TF_Support Mar 18 '20 at 06:00

2 Answers2

1

You can try the solution stated here.

As per the discussion:

Step 1: Create a directory structure like this:

- main.py  # Your code goes here
- hooks
   - hook-tensorflow.py

Step 2: Copy the following into hook-tensorflow.py:

from PyInstaller.utils.hooks import collect_all


def hook(hook_api):
    packages = [
        'tensorflow',
        'tensorflow_core',
        'astor'
    ]
    for package in packages:
        datas, binaries, hiddenimports = collect_all(package)
        hook_api.add_datas(datas)
        hook_api.add_binaries(binaries)
        hook_api.add_imports(*hiddenimports)

Step 3: When compiling, add the command line option --additional-hooks-dir=hooks

Step 4: Simply add the full import name into the packages list.

The main.py file contains the following code from tensorflow import *

TF_Support
  • 1,794
  • 1
  • 7
  • 16
  • Thank you, for you'r answer. I followed your steps, but now it's showing error at the time of converting EXE file. I added 'pywrap_tensorflow' at packages = [ ] list. and i got following error – Mohammad Al-Amin Mar 18 '20 at 09:53
  • 29583 INFO: Determining a mapping of distributions to packages... 38610 WARNING: Unable to find package for requirement protobuf from package tensorflow. 38610 WARNING: Unable to find package for requirement termcolor from package tensorflow. 38610 WARNING: Unable to find package for requirement absl-py from package tensorflow. 38610 WARNING: Unable to find package for requirement six from package tensorflow. 38610 WARNING: Unable to find package for requirement google-pasta from package tensorflow. 38610 WARNING: Unable to find package for requirement grpcio from package tensorflow. – Mohammad Al-Amin Mar 18 '20 at 09:54
  • 38610 INFO: Packages required by tensorflow: ['opt_einsum', 'wheel', 'tensorflow_estimator', 'scipy', 'keras_applications', 'numpy', 'wrapt', 'keras_preprocessing', 'astor', 'gast', 'tensorboard'] 38626 WARNING: Unable to copy metadata for tensorflow_core: The 'tensorflow_core' distribution was not found and is required by the application – Mohammad Al-Amin Mar 18 '20 at 09:55
  • 2020-03-18 15:35:34.572792: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found 2020-03-18 15:35:34.577535: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2020-03-18 15:35:37.469511: E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/model_to_estiamtor – Mohammad Al-Amin Mar 18 '20 at 09:55
  • 42958 WARNING: Unable to determine requirements for tensorflow_core: The 'tensorflow_core' distribution was not found and is required by the application 43623 INFO: Packages required by astor: [] 43647 WARNING: Unable to copy metadata for pywrap_tensorflow: The 'pywrap_tensorflow' distribution was not found and is required by the application Traceback (most recent call last): – Mohammad Al-Amin Mar 18 '20 at 09:56
  • File "", line 2, in ImportError: No module named 'pywrap_tensorflow' Traceback (most recent call last): File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 321, in get_module_file_attribute attr = loader.get_filename(package) AttributeError: 'NoneType' object has no attribute 'get_filename' During handling of the above exception, another exception occurred: – Mohammad Al-Amin Mar 18 '20 at 09:58
  • Traceback (most recent call last): File "c:\users\manash\appdata\local\programs\python\python35\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\manash\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Manash\tesorflow\Scripts\pyinstaller.exe\__main__.py", line 7, in File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\__main__.py", line 114, in run run_build(pyi_config, spec_file, **vars(args)) – Mohammad Al-Amin Mar 18 '20 at 09:58
  • File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\building\build_main.py", line 422, in assemble self.graph.process_post_graph_hooks() File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\depend\analysis.py", line 311, in process_post_graph_hooks module_hook.post_graph() File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\depend\imphook.py", line 421, in post_graph self._process_hook_func() – Mohammad Al-Amin Mar 18 '20 at 10:00
  • File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\depend\imphook.py", line 440, in _process_hook_func self._hook_module.hook(hook_api) File "C:\Ne folder\hooks\hook-tensorflow.py", line 12, in hook datas, binaries, hiddenimports = collect_all(package) File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 1000, in collect_all datas += collect_data_files(package_name, include_py_files) – Mohammad Al-Amin Mar 18 '20 at 10:00
  • File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 723, in collect_data_files pkg_base, pkg_dir = get_package_paths(package) File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 537, in get_package_paths file_attr = get_module_file_attribute(package) File "c:\users\manash\tesorflow\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 339, in get_module_file_attribute raise ImportError **ImportError** @TF_Support – Mohammad Al-Amin Mar 18 '20 at 10:00
0

I have solved this error by changing my Python(3.7 to 3.5), tensorflow(2 to 1.15) version.