AttributeError on importing tensorflow.keras

434 views
Skip to first unread message

renscy

unread,
Aug 4, 2019, 8:17:53 AM8/4/19
to PyInstaller

I tried..

* using:
hidden-imports

* modifying pathex of the spec file to include the directory path of the module, which is retrieved from:
import tensorflow as tf

print(tf.keras.__file__)

And I'm currently at my wit's end trying to figure this out.

The whole error is:
D:\Shared\CMSC\190-2\readr>readr.exe
Limited tf.compat.v2.summary API due to missing TensorBoard installation
Limited tf.summary API due to missing TensorBoard installation
Traceback (most recent call last):
 
File "main.py", line 4, in <module>
   
from modules.model import models
 
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
 
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
 
File "d:\shared\cmsc\190-2\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
   
exec(bytecode, module.__dict__)
 
File "modules\model.py", line 4, in <module>
    models
= load_models(n=num_models)
 
File "modules\ai.py", line 28, in load_models
    model
= tf.keras.models.load_model(os.path.join('.', 'models', ('m' + str(i) + 'eF.h5')))
AttributeError: module 'tensorflow' has no attribute 'keras'
[11288] Failed to execute script main

Basic requirements of my project:
numpy==1.16.4
opencv
-python==4.1.0.25
pandas
==0.25.0
PyInstaller==3.5
tensorflow
==2.0.0a0

The actual requirements of my project, when I use pip freeze:
numpy==1.16.4
opencv
-python==4.1.0.25
pandas
==0.25.0
PyInstaller==3.5
tensorflow
==2.0.0a0


The extended requirements (downloaded and installed too when installing the basic requirements):



absl
-py==0.7.1
altgraph
==0.16.1
astor
==0.8.0
future
==0.17.1
gast
==0.2.2
google
-pasta==0.1.7
grpcio
==1.22.0
h5py
==2.9.0
Keras==2.2.4
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
Markdown==3.1.1
numpy
==1.17.0
opencv
-python==4.1.0.25
pandas
==0.25.0
pefile
==2019.4.18
protobuf
==3.9.0
PyInstaller==3.5
python
-dateutil==2.8.0
pytz
==2019.1
pywin32
-ctypes==0.2.0
PyYAML==5.1.2
scipy
==1.3.0
six
==1.12.0
tb
-nightly==1.14.0a20190301
tensorflow
==2.0.0a0
termcolor
==1.1.0
tf
-estimator-nightly==1.14.0.dev2019030115
Werkzeug==0.15.5

Very minimal code to reproduce the error:

from tensorflow import keras
model
= keras.load_model(`./model.hf5`)

Please help me. This is plaguing me now for days. Thanks!

Vincent Le Goff

unread,
Aug 5, 2019, 4:06:17 AM8/5/19
to pyins...@googlegroups.com

Just a thought: when you say you have tried specifying hidden imports, you've tried 'tensorflow.keras'?  I had a very similar problem, one relying partly on dynamic import PyInstaller couldn't figure out.  Adding the path name as a hidden import solved the issue, told it to package my dynamic module with no issue.


I hope things are that simple.


Cheers,


Vincent

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/b4426f10-8d84-4051-a0f0-d39358dc249b%40googlegroups.com.

renscy

unread,
Aug 6, 2019, 4:37:35 AM8/6/19
to PyInstaller
I solved it:

I just downgraded to Tensorflow 1.14.0 and did the hidden import. Apparently PyInstaller has some issues with Tensorflow 2.0.0a0
To unsubscribe from this group and stop receiving emails from it, send an email to pyins...@googlegroups.com.

Hamed Majidifard

unread,
Sep 23, 2019, 1:20:20 PM9/23/19
to PyInstaller
I have a problem to convert a python code to an executable file because it has tensorflow package inside it. After converting the file when I was trying to run it I got this error. the error is "ModuleNotFoundError: No module named 'tensorflow_core.python'
How can I import hidden?
Reply all
Reply to author
Forward
0 new messages