A memo that I made a trial and error to run the created machine learning program in a Windows environment where Python is not installed.
The environment is as follows
$ pip install pyinstaller
$ pyinstaller main.py --onefile
With this, the Python execution environment and related libraries are also combined into one exe file.
However, if there is a dependency that PyInstaller cannot resolve, the created exe file will throw an error.
In that case, build without using the --onefile
option and solve the following two points one by one.
* .so not found
You are not importing the binaries of the external libraries you depend on. It seems that PyInstaller automatically imports what is directly referenced, but it seems that it does not consider what is indirectly referenced.
You can specify to explicitly include it with the --add-binary
option.
Note that the method of specifying Path is special
--add-binary "<Relative path of the source SO file>;<Run-time relative path of the destination directory>"
The cache seemed to be bad, so with the --clean
option, it was placed as specified.
ModuleNotFoundError
Similarly, the external library is not imported here either. It seems that the one that is indirectly referenced in the Python library system corresponds. You can specify it with hidden-import when executing pyinstaller. While adding, repeat exe conversion and continue until ModuleNotFoundError disappears.
For example, when I made a text classification program using tensorflow, it looked like this.
$ pyinstaller main.py ¥
--hidden-import=tensorflow.python.keras.engine.base_layer_v1 ¥
--hidden-import=tensorflow.python.ops.while_v2 ¥
--hidden-import=tensorflow.python.ops.numpy_ops
For example, it looks like this.
$ pyinstaller main.py --onefile -y --clean \
--hidden-import=tensorflow.python.keras.engine.base_layer_v1 \
--hidden-import=tensorflow.python.ops.while_v2 \
--hidden-import=tensorflow.python.ops.numpy_ops \
--add-binary "../../../../AppData/Local/Programs/Python/Python36/lib/site-packages/tensorflow/lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so;tensorflow/lite/experimental/microfrontend/python/ops"