[PYTHON] Convert the program that imports Google's client library to .exe with pyinstaller

I had to convert a program that uses Google Speech to Text into an .exe, but I was addicted to it, so I made a note.

environment

OS Windows10 (At pipenv) Python 3.7.4 pyinstaller 3.6

Command executed

*** Convert test.py to .exe. Assuming ***

pyinstaller test.py --onefile

ERROR1 First of all, when I run it normally, I get the following error

pkg_resources.DistributionNotFound: The 'google-cloud-core' distribution was not found and is required by the application

This error can be resolved by using the --additional-hooks-dir option at startup, creating a file like the one below, and giving the path to the folder. I often see articles like this, but *** I couldn't solve it in my environment. *** ***

hook-google.cloud.py


from PyInstaller.utils.hooks import copy_metadata
try:    datas = copy_metadata('google-cloud-core')
except: datas = copy_metadata('google-cloud-speech')

↓ I get this error

    assert self.hook_module_name not in HOOKS_MODULE_NAMES
AssertionError

This problem was usually solved by installing google-cloud-core again. .. ..

pip install google-cloud-core

ERROR2 After installing google-cloud-core, it can be executed and .exe is also generated, but when the generated .exe is executed, the following error (or Exception?) Appears this time.

Exception ignored in: 'grpc._cython.cygrpc.ssl_roots_override_callback'
E0603 18:31:14.600000000 16632 src/core/lib/security/security_connector/ssl_utils.cc:482] assertion failed: pem_root_certs != nullptr

It seems to be around license authentication. Here, if you create a folder called hooks in the same hierarchy as test.py and create and install the following files in it,

hook-grpc.py


from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')

If you rebuild with the following command, it will not appear

pyinstaller test.py --onefile --additional-hooks-dir=./hooks/

reference

https://github.com/pyinstaller/pyinstaller/issues/3935 https://teratail.com/questions/201443 https://teratail.com/questions/118297 https://qiita.com/akitooo/items/eb82a5f335d8ca9c9faf https://stackoverflow.com/questions/54634035/my-pyinstaller-is-giving-assertion-error-when-i-execute-it https://stackoverflow.com/questions/40076795/pyinstaller-file-fails-to-execute-script-distributionnotfound https://www.bountysource.com/issues/86848733-pyinstaller-3-6-assertionerror https://github.com/googleapis/google-cloud-python/issues/5774

Recommended Posts

Convert the program that imports Google's client library to .exe with pyinstaller
PyInstaller memorandum Convert Python [.py] to [.exe] with 2 lines
How to get the directory where the EXE built with Pyinstaller exists
EXE the application created with PyQt5 with PyInstaller
I tried using the Python library "pykakasi" that can convert kanji to romaji.
I want to exe and distribute a program that resizes images Python3 + pyinstaller
Convert the image in .zip to PDF with Python
Convert 202003 to 2020-03 with pandas
Try to play with the uprobe that supports Systemtap directly
Settings to debug the contents of the library with VS Code
Convert images to sepia toning with PIL (Python Imaging Library)
[Python Kivy] How to create an exe file with pyinstaller
[Golang] A program that determines the turn with random numbers
The story that the private key is set to 600 with chmod
How to start the program
When I run the exe file with pyinstaller, my PC crashes.
Try to write a program that abuses the program and sends 100 emails
For the time being, I want to convert files with ffmpeg !!
I made a program that automatically calculates the zodiac with tkinter
Python script written in PyTorch is converted to exe with PyInstaller
[Python] A program that rotates the contents of the list to the left