I am having a problem when I generate an exe file with pyinstaller. My code runs okay when I execute using the python interpreter but when I generate the exe file using the PyInstaller I get a GRPC error.
Error: Exception in 'grpc._cython.cygrpc.ssl_roots_override_callback' ignored E0807 20:38:36.262000000 10808 src/core/lib/security/security_connector/security_connector.cc:1173] assertion failed: pem_root_certs != nullptr
The error happen when I try to execute a long_running_recognize.
Any tips regarding this problem?
@wcordeiro I'm not really familiar with pyinstaller. We have had a couple of reports of packaging-related issues with it:
In your case, it looks as though the SSL root certificates are not present in the pyinstaller-generated EXE. There are a couple of reports of similar problems, e.g. for requests:
And this recipe:
I don't think there is anytihng we can do in google-cloud-* to fix this issue. Please feel free to keep discussing it here, though.
I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/
a = Analysis(
...
binaries=binaries,
datas=[
('roots.pem', 'grpc/_cython/_credentials/'),
],
This will pack the pem file with the app, and it will find it right away.
I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/
a = Analysis( ... binaries=binaries, datas=[ ('roots.pem', 'grpc/_cython/_credentials/'), ],This will pack the pem file with the app, and it will find it right away.
Thanks, this helped me a lot.
I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/
a = Analysis( ... binaries=binaries, datas=[ ('roots.pem', 'grpc/_cython/_credentials/'), ],This will pack the pem file with the app, and it will find it right away.
I have the same issue, so, where to copy the file you mentioned?
I have the same issue, so, where to copy the file you mentioned?
I copied to my main folder, together with my python code file, so the code above pack them in the folder 'grpc/_cython/_credentials/' in your generated pyinstaller dir.
A PyInstaller hook called hook-grpc.py looking like this would do the trick:
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')
Will open a PR on the PyInstaller repo for that.
Is this solution a security risk as pem files include certificates?
@cbenhagen It did work. I have been trying for whole day today to convert my python code to .exe file.
It was a pretty tough journey. First with pyinstaller or cx_Freeze, both giving lots of errors and bit by bit I improved by the pyinstaller approach.
.....
After many hours of resolving errors, I solved the problem.
Though you didn't tell in the above code where to put the hook-grpc.py file.
Let me add on.
It should be placed in :
.............
C:\Users\ujjwa\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller\hooks
................
Here replace just the initial username and python version if necessary.
Or if you are still not getting the destination,:
Thanks very much @rising-stark and @cbenhagen for your help!
In my case it was under C:\Python39\Lib\site-packages\PyInstaller\hooks, but I'm sure this varies per installation. Once recreated, the executable worked perfectly writing to my Firebase Firestore project.
@rising-stark Thanks! Worked for me :) 馃憤馃徎
Most helpful comment
A PyInstaller hook called
hook-grpc.pylooking like this would do the trick:Will open a PR on the PyInstaller repo for that.