tkroot.tk.call() raises an error after making the exe file - python-3.x

My .py file is working with no errors. But after making exe file using pyinstaller and when I run the exe file, it gives following error;
File "site-packages\TkinterDnD2\TkinterDnd.py, line 271, in __init__
File "site-packages\TkinterDnD2\TkinterDnd.py, line 41, in _require
RuntimeError: Unable to load tkdnd library.
I checked the lines mentioned above in TkinterDnd.py and found that it raises a runtime error due to tkroot.tk.call() function.
Please help me to correct this error.

When you build EXE with pyinstaller try add
--hidden-import TkinterDnD2

Related

Pyinstaller stuck when including tensorflow-cpu and tensorflow-directml-plugin

I am trying to create a single executable file with pyinstaller, I have installed in my environment tensorflow-cpu==2.9 and tensorflow-directml-plugin==0.0.1.dev220621 I used this because I have an intel GPU where I want to run a tensorflow model. I found this solution in here. When I run the script in visual studio code it runs without a problem and the model runs in the GPU, but when I try to make it exe file with pyinstaller it gets stuck in this message:
F tensorflow/c/experimental/stream_executor/stream_executor.cc:808] Non-OK-status: stream_executor::MultiPlatformManager::RegisterPlatform( std::move(cplatform)) statum( std::move(cplatform)) status: INTERNAL: platform is already registered with name: "DML"
Also before that message, it spams a lot this:
2022-07-20 15:01:23.929010: I tensorflow/c/logging.cc:34] Successfully opened dynamic library dxgi.dll
2022-07-20 15:01:23.930664: I tensorflow/c/logging.cc:34] Successfully opened dynamic library d3d12.dll
2022-07-20 15:01:23.993556: I tensorflow/c/logging.cc:34] DirectML device enumeration: found 1 compatible adapters.
2022-07-20 15:01:26.072697: I tensorflow/c/logging.cc:34] Successfully opened dynamic library C:\Users\xx\Documents\DMLEnvironment\lib\site-packages\tensorflow-plugins/directml/directml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.dll
I tried uninstalling tensorflow-cpu and installing the normal tensorflow, but then the script did not run. I think there is a conflict between tensorflow-cpu and tensorflow-directml-plugin but I find it weird that it works if I run the script directly from visual studio code.
Any idea of why this could be happening?
P.S. I am using virtual environment with python 3.8 and pyinstaller 5.2
Update:
I managed to make it work with Pyinstaller 4.10 and there is a problem:
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "tensorflow\__init__.py", line 37, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "tensorflow\python\__init__.py", line 37, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "tensorflow\python\eager\context.py", line 33, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "tensorflow\python\pywrap_tfe.py", line 25, in <module>
ImportError: DLL load failed while importing _pywrap_tfe: Die angegebene Prozedur wurde nicht gefunden.
[13284] Failed to execute script due to unhandled exception!
I managed to solve this problem by adding the .pyd file in my .spec file in the data option like:
datas=[
("DMLEnvironment/Lib/site-packages/tensorflow/python/_pywrap_tfe.pyd", "tensorflow/python"),
],
but the exe file (onefile) does not run the tensorflow-directml-plugin because my model is still running in the CPU and not the GPU. I tried to put tensorflow-directml-plugin package as a hidden import in the .spec file but this didn't work.

How to create kivy applications for desktop in Windows?

Good afternoon people.
Once again trying to package kivy for DESKTOP on WINDOWS 10 and to no avail!
I had a lot of errors that I managed to solve without disturbing the order in the groups but this one is phoda with ph.
1 - I create the exe using Auto_py_to_exe and before there is any comment that I should use pyinstaller, I tell you, the same thing happens!
2 - My pyinstaller script is as follows:
pyinstaller --noconfirm --onefile --console --name "TeuCu" --add-data "C: /Users/Elias/Desktop/kv_inventario/inventario/main.kv ;." --add-data "C: / Users / Elias / Desktop / kv_inventario / inventario / images; images /" "C: /Users/Elias/Desktop/kv_inventario/inventario/main.py"
3 - The error is exactly like this, when running the application after it is created it returns this error:
[CRITICAL] [Window] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
File "kivy\core\__init__.py", line 70, in core_select_lib
File "kivy\core\window\window_sdl2.py", line 152, in __init__
File "kivy\core\window\__init__.py", line 982, in __init__
File "kivy\core\window\window_sdl2.py", line 311, in create_window
File "kivy\core\window\__init__.py", line 1268, in create_window
File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
File "kivy\core\image\__init__.py", line 561, in __init__
File "kivy\core\image\__init__.py", line 754, in _set_filename
File "kivy\core\image\__init__.py", line 460, in load
File "kivy\core\image\__init__.py", line 223, in __init__
File "kivy\core\image\img_sdl2.py", line 47, in load
[CRITICAL] [App] Unable to get a Window, abort.
My solution that could possibly work would be this tip that I found in kivy issues:
Kivy issues
This took me to the post below and translating it asks to uninstall the pillow and reinstall with the wheel
python3 -m pip3 uninstall pillow
python3 -m pip3 install --use-wheel pillow
But it didn't.
I would like your help. Who managed to generate an application for Windows with kivy
I'm using Windows 10 to package.
This error is common - Here are some helpful links:
Kivy not working (Error: Unable to find any valuable Window provider.)
Python app not working after using pyinstaller but doesn't give any errors
https://github.com/kivy/kivy/issues/6342
https://github.com/pal1000/save-legacy-intel-graphics
Kivy does not detect OpenGL 2.0
Windows- Pyinstaller Error "failed to execute script " When App Clicked
Unable to get a window, abort
https://pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html
https://github.com/kivy/kivy/issues/6276
If none of these work, I also made a video on packaging a kivy app to a single exe for Windows: https://www.youtube.com/watch?v=k9Hx0q5Sopg
Please let me know if you succeed. Cheers!

failing to build python script to .exe with correct conda environment

I've tried using pyinstaller, py2exe and auto-py-to-exe but keep having similar problems. First, py2exe seems to be abandoned, but pyinstaller and auto-py-to-exe correctly build an exe that can run, and run the beginning of my code, however when I try to load a pickled model using joblib dump/load I get the following error. This is the same error I get when I run the python script in the wrong environment.
How can I build from the correct conda environment?
**Traceback (most recent call last):
File "test.py", line 43, in <module>
File "test.py", line 24, in main
File "site-packages\joblib\numpy_pickle.py", line 598, in load
File "site-packages\joblib\numpy_pickle.py", line 526, in _unpickle
File "pickle.py", line 1088, in load
File "pickle.py", line 1376, in load_global
File "pickle.py", line 1426, in find_class
ModuleNotFoundError: No module named 'sklearn.mixture._gaussian_mixture'
[12708] Failed to execute script test**

Pyinstaller does not look for the file inside the Python Virtual Environment

I want to convert Python code into standalone executable , the code uses numpy, scipy, and Pymc3 modules. I am using Python 3.6.4. I have created the project using Virtual Environment in Pycharm IDE. The command that I used to run pyinstaller is as follows:
venv/Scripts/pyinstaller --onefile src/POD.py
venv being the folder where virtual environment is stored and src being the folder where my Python source code ie. POD.py is saved. Pyinstaller runs just fine generates some warning message, but when I try to run the executable generated by pyinstaller it thrown as error
Traceback (most recent call last):
File "POD.py", line 196, in <module>
File "POD.py", line 79, in train
File "Lib\site-packages\theano\tensor\var.py", line 155, in __mul__
File "Lib\site-packages\theano\gof\op.py", line 615, in __call__
File "Lib\site-packages\theano\tensor\elemwise.py", line 482, in make_node
File "Lib\site-packages\theano\tensor\elemwise.py", line 438, in get_output_info
File "Lib\site-packages\theano\tensor\elemwise.py", line 157, in __init__
File "Lib\site-packages\theano\gof\op.py", line 1308, in __init__
File "Lib\site-packages\theano\gof\op.py", line 1331, in load_c_code
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI126642\\theano\\tensor\\c_code\\dimshuffle.c'
[4756] Failed to execute script POD
Seems like it is trying to find the file dimshuffle.c outside of the virtual environment. In-fact the I can see that there is folder inside virtual environment which has the dim_shuffle.c code. I can find it inside virtual environment in following folder.
venv/Lib/site-packages/theano/tensor/c_code/dimshuffle,c
My question is how do I instruct pyinstaller to look for dimshuffle inside virtual environment folder?
You can,
extend the sys.path by editing the spec file.
pyi-makespec --paths=/path/to/thisdir \
--paths=/path/to/otherdir myscript.py
List the hidden imports using the spec file.
for more info refer this

How do I make PyInstaller bundle Tcl/Tk for OSX targets? - Import Error Tcl/Tk modules not found - Pyinstaller on Mac is not working

I have a frustrating problem that set me back a day trying to get an executable file from my finished bookstore app.
I used the Pyinstaller --onefile --windowed bookstore.py from the main project menu, also vm/bin/Pyinstaller --onefile --windowed bookstore.py which created the .exe and .app file successfully.
HOWEVER, when running the .app file, nothing happens. It starts, and just disappears.
I ran the core executable from the cli on Mac from the main project folder with open dist/bookstore.app/Contents/Macos/bookstore and, loads of research and over 20 variations of code and file changes later, I got the same same trackback (N.B. different file path for global Pyinstaller) error message back from the console.
Traceback (most recent call last):
File "bookstore.py", line 5, in <module>
File "/Users/jmulhall/Documents/Documents/Python_Project_Folder/Python3_Training/ProjectBookstore/vm/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "tkinter/__init__.py", line 36, in <module>
File "/Users/jmulhall/Documents/Documents/Python_Project_Folder/Python3_Training/ProjectBookstore/vm/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: dlopen(/var/folders/0d/6l_1mgwn4cxbrx21_nm7l8gh0000gn/T/_MEIHyYK9G/_tkinter.so, 2): Library not loaded: #loader_path/Tcl
Referenced from: /var/folders/0d/6l_1mgwn4cxbrx21_nm7l8gh0000gn/T/_MEIHyYK9G/_tkinter.so
Reason: image not found
[3899] Failed to execute script bookstore
My Mac details are as follows:
MacOs High Sierra V 10.13.3 with a standard HD on a mid 2012 Macbook Pro
My Software versions are python 3.6.4, pyinstaller 3.3.1 , virtualenv 15.1.0, sqllite3 3.19.3
The most promsing fix on github did not work ergo my query on fixing the Pyinstaller issue for mac where it loads the tcl and tk resources. The links I followed are here:​
Main Query Link - Github​,
Support File Changes Demo for hooks​
I created a pyinstaller-hooks folder and inserted the hook and pyruntime hooks file into the folder with the tclResources and tkResources name changes in the files as follows:
This did not work.
And I am still getting the above stack trace despite running the new command, picking up the new pyinstaller-hooks folder files in the main project folder, as follows:
pyinstaller --onefile --windowed --additional-hooks-dir pyinstaller-
hooks --runtime-hook pyinstaller-hooks/pyi_rth__tkinter.py bookstore.py
Why is it still not finding the the new files with Tree() and os.path.join()) functions altered to tkResources/tclResources and thus crashing the app when it tries to launch. I could not test the .exe as I have only a Mac environment so Im only focused on the .app right now. Can anybody help with this?
Nearly forgot, my main project folder view is as follows:

Resources