Exception in GRPC when trying to execute Google Cloud API - python

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?

Create hook-grpc.py in the hooks folder (\Lib\site - packages\PyInstaller\hooks) and put the following code.
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files ( 'grpc' )
If this doesn't work, then go to \Lib\site - packages\PyInstaller\hooks and add the following code to hook-google.cloud.py file.
datas += copy_metadata ( 'google-cloud-firestore' )

To resolve this I did the following
1.) create a hook-grpc with the following code
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')
2.) saved this file the location C:\Users\swap***\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyInstaller\hooks (this will vary as per the installation)
3.) Re create the exe file using the PyInstaller
command to create the file is below
pyinstaller --onefile pythonScriptName.py (replace this"pythonScriptName" with your file name)

https://github.com/grpc/grpc/issues/9223 looks similar with this issue.

Related

App using TKinterModernThemes made with PyInstaller gives the error "invalid command name "set_theme""

I've been trying to make an app using tkinter, TKinterModernThemes, and turn it into an executable with PyInstaller, and I've had no luck. Every time I try to use any kind of module using ttk themes, I run into some sort of error. I decided to settle on using the TKinterModernThemes module. Making an exe using PyInstaller gives me the following error:
File "TKinterModernThemes\__init__.py", line 66, in __init__
_tkinter.TclError: invalid command name "set_theme"
I've tried including both tkinter and TKinterModernThemes as a hidden import in PyInstaller, trying with and without --onefile, and using Nuitka instead (same error). Any help would be wonderful.
I changed manually my path here ThemedTKinterFrame.__init__, at line 64 like this
self.root.tk.call("source", "/home/pi/.local/lib/python3.7/site-packages/TKinterModernThemes/themes/" + theme.lower() + "/" + theme.lower() + ".tcl")
and it works.
pyinstaller --noconsole --onefile --collect-data TKinterModernThemes --collect-data PIL .\FILENAME.py
SAVED MY LIFE!!!
This is now fixed in version 1.9.0 - the issue was the '/../' that I had in the library to move up a directory - the os.path.abspath handles this better.

Use my own python libraries in visual studio code on raspberry pi

I have a directory that contains sub directories of code that I reuse.
MyBaseDirectory
\genericcodedir1
reuse1.py
\simpleapp1
app1.py
app1.py has the following line
import reuse1
Visual studio will fail to run this since it says it can't find the library.
On windows I simply added the genericcodedir1 to the PYTHONPATH environment variable and all is well.
What should I do on the raspberry pi to allow this to run?
error message:
Exception has occurred: ModuleNotFoundError
No module named 'reuse1'
File "/home/pi/Desktop/Mybasedirectory/simpleapp1/app1.py", line 5, in <module>
import reuse1
I assume you have file structure like this and you open Test folder in VS Code As follows.
You can specify the path by adding the following code above the import statement in app.py:
import sys
sys.path.append("./genericcodedir1")
import reuse1
In addition, you can add the following configuration to the settings.json file to make vscode recognize reuse1.
{
"python.analysis.extraPaths": [
"./genericcodedir1"
]
}
code and result
so if your files looks like :
|_genericcodedir
|_reuse1.py
|_simpleapp1
|_app1.py
you need to add an empty file called __init__.py in your genericcodedir.
another note worthy thing is your working directory (the directory in which your terminal runs)
you may need to append to os path depending on where you are when launching the program

Pyinstaller failed to execute script: FileNotFoundError: No file or directory: 'C:\\Users\\etc'

I have a python file I am converting to exe via Pyinstaller. The coversion runs fine with no error, however when I run the exe file I get error in line 13 of the python file (line is import librosa). Then I get a bunch of files and then a
FileNotFoundError: No file or directory: 'C:\\Users\\johnny\\Appdata\\Local\\Temp\\_MEI70722\\librosa\\util\\example_data\\registry.txt'.
Also the python file itself runs fine.
Any help would be appreciated
PyInstaller tries to find all the dependencies, however this file is not imported but loaded so it misses it. You can simply force it to add it:
--add-data [path to your python]/Lib/site-packages/librosa/util/example_data;librosa/util/example_data
With The full command be like :
pyinstaller --onefile [YourScript].py --add-data [path to your python]/Lib/site-packages/librosa/util/example_data/registry.txt;librosa/util/example_data
You'll need to specify the data files as PyInstaller hooks.
Create a folder "extra-hooks", and in it a file "hook-librosa.py"
paste these 2 lines in "extra-hooks/hook-librosa.py":
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('librosa')
Then tell PyInstaller where to locate this file with adding 1 of the following to your PyInstaller command:
--additional-hooks=extra-hooks
--additional-hooks-dir "[PATH_TO_YOUR_PROJECT]/axtra-hooks"
The 2nd one worked for me, and I was using auto-py-to-exe, built on PyInstaller.
I guess the file doesn't exist. Open a file manager and copy the directory.
In the PyInstaller, you should type in the python file's name and then --onefile. It makes an .EXE file (if you are on windows) with all the imported files within. You can learn more here: https://pyinstaller.readthedocs.io/en/stable/usage.html

Failed to load dynlib/dll (Pyintaller)

After using the pyintaller to transfer the py file to exe file, the exe file throws the error: "Failed to load dynlib/dll". Here is the error line:
main.PyInstallerImportError: Failed to load dynlib/dll 'C:\Users\YANGYI~1\AppData\Local\Temp\_MEI215362\sklearn\.libs\vcomp140.dll'.
Most probably this dynlib/dll was not found when the application was
frozen. [1772] Failed to execute script 2
after get this, I did check the path and I did not find a folder called "_MEI215362" in my Temp folder, I have already made all files visible. Also, I have re-download the VC but and retransferring the file to exe, but it didn't work. Any ideas how to fix the issue? Thank you in advance!
# I solved this exact problem by adding this to the spec file:
b = [
('C:\\path to python\\Python\\Python38\\Lib\\site-packages\\sklearn\\.libs\\vcomp140.dll', '.\\sklearn\\.libs')
]
and then
a = Analysis(['pythonFilename.py'],
pathex=[],
**binaries=b,**
datas=[] # , .....
)
I also encountered a similar problem like Martin.
In my case, however, it was the ANSI64.dll missing...
So, I simply put the particular dll file into the dist directory.
Lastly, I keep the exe and related raw data files (e.g. xlsx, csv) inside the "dist" folder and to run the compiled program. It works well for me.

openpyxl not working as EXE

Error message from running my exe:
ModuleNotFoundError: No module named 'openpyxl'
testHi.py
#simple test to see if openpyxl module works
import openpyxl
print ("hi")
input()
hook-openpyxl.py
# taken from pyinstaller dev team, store in same dir as testHi.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
cmd line input:
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
I run the the hiTest and get the error above.
I have looked everywhere for this solution. Can anyone tell me what I am doing wrong.
I fixed my issue by installing it through Pip, rather than install the package through Pycharm, and Pyinstaller was able to find the package.
I got the idea from looking through the text in the command prompt and saw it was loading modules that I had installed via Pip and not through Pycharm.
I was able to get this working using auto-py-to-exe (which uses pyinstaller) by including the following folders/files from my python library into the same folder that I run pyinstaller from:
jdcal.py
openpyxl (folder)
et_xmlfile (folder)
pyinstaller command:
pyinstaller -y -F "[directory]/myscript.py"
Notes on Library Location:
Windows library location for me was: C:\users[username]\AppData\Local\Programs\Python\Python37-32\Lib
The packages were in the "site_packages" folder
use
--hiddenimport openpyxl
long with the previous solutions, it worked for me, I was able to enforce the import of openpyxl.
You was quite close. :-)
I fixed the problem by modifying the "hook-openpyxl.py" file. The command collect_data_files('openpyxl') actually returns an empty list. But there is another command collect_submodules which seems to do what we want. So my "hook-openpyxl.py" file looks like this.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('openpyxl')
I placed the "hook-openpyxl.py" file in the same directory like my spec file. In the spec file I set to location of the new hook file
a = Analysis(
...
...
hookspath=['.'],
...
...
...
I guess, you will have the same result with your command line parameter
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
My environment
Python=3.8
openpyxl=3.0.10
PyInstaller=4.8

Categories

Resources