I am trying to bundle a python application using pyinstaller that uses tensorflow.
I am now using Pyinstaller-4.0.dev0+2f4426f52, Tensorflow 2.0, Keras 2.3 and Python 3.7.3 all in a virtual environment.
I have tried various older versions, but each older version had a different issue that I could not resolve. I have dedicated 3 days to trying to solve this problem.
A simplified example of the script I am running is:
from tensorflow import keras
model = keras.Sequential()
I used the following command to run pyinstaller:
pyinstaller --noconfirm --log-level=DEBUG ^
--onedir ^
--clean ^
--name MyModel ^
--hidden-import=tensorflow_core ^
--noupx ^
main.py
Using hidden-import appears to be redundant, as the output states:
DEBUG: Hidden import 'tensorflow_core' already found
There were no build errors or warnings in the log.
I have looked into the pyz-00.pyz file and can confirm that TensorFlow modules are included in the file. I confirmed that the archive contains:
'tensorflow_core.python': (1, 9871434, 2355),
However when I try to run the exe I get the following error:
File "site-packages\tensorflow_core\python_init_.py", line 49, in ImportError: cannot import name 'pywrap_tensorflow' from 'tensorflow_core.python' (\dist\MyModel\tensorflow_core\python_init_.pyc)
It appears that pyinstaller can't deal with tensorflow, and I wondered whether anyone with experience here might know how to write a hook for it or knows of some other workaround?