TkDnd working in Spyder but gives error after converting .exe - python-3.x

I am creating one application which sorts files and merges them based filename. I needed filepaths when i drop files from file browser to my widget's listbox. For Tkinter i installed TkDnd. I followed instructions from How to Install and Use TkDnD with Python 2.7 Tkinter on OSX? and it worked for me. I am using Anaconda and i paced folders in C:\Users\Anaconda3\tcl and C:\Users\Anaconda3\Lib\site-packages. I am using Spyder and python 3.7. I made executable from below command:
pyinstaller --onefile -w PDF_Merger.py
After opening file it gives me error:
Fatal error ".py failed to execute"
I know this problem is regarding linking TkDnd.
I have tried making executable with --onedir and it still gives me error. But after copying tkdnd2.8 to dist it works.
Here is my code using TkDnd:
from TkinterDnD2 import *
widget = TkinterDnD.Tk()
filesinfileslist = Variable(widget)
FilesShow = ReorderableListbox(widget, font=('aerial',12), height = 23 , width = 45, listvariable = filesinfileslist, selectmode = EXTENDED)
FilesShow.place(x=10, y=40)
FilesShow.drop_target_register(DND_FILES)
FilesShow.dnd_bind('<<Drop>>', drop)
drop method takes only pdf files and sets it to listBox.
As of now it works in spyder but .exe file gives me error. Can anyone show me how to resolve this issue or if i made some errors in code?

I resolved this issue with adding files from tkdnd2.8 folder with --add-data attribute while generating executable with pyinstaller. I was able to create it with onefile.

This post is already a few years old but I got to it when I looked for my problem. In the end I solved it like this:
pyinstaller --onefile --add-data=C:\ProgramData\Anaconda3\tcl\tkdnd2.8\;' myfile.py

Related

How to freeze my Python code with PyInstaller when the exe says it miss some files?

I am using Python 3.7.9 with Pyinstaller 5.0.1
I am trying to freeze my code which uses pyshadow.
When I execute it from Pycharm it works fine.
When I execute the exe after I freezed the code, I get this error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\gauth\\AppData\\Local\\Temp\\_MEI233082\\pyshadow\\resources\\querySelector.js
This could be a common issue when your python code uses some specific module that needs some third files. In my case, it is about pyshadow missing a JS file.
So I add this file 'querySelector.js' in the freezing command:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --add-data "querySelector.js;." main.py
But I still get the same error.
Does anyone have any idea how to fix this issue?
Thanks to rokm. I get his help from the git forum of the PyInstaller developer (full details here: https://github.com/pyinstaller/pyinstaller/discussions/6905). I publish his answer here in case someone has the same issue.
I had to add the parameter:
--collect-data pyshadow
So my final command is:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --collect-data pyshadow main.py
ANd it works like a charm!

"Error loading Python lib" when trying to run a python script as an executable

I am hoping to turn my python3 script into a distributable application but I'm having trouble turning the script into an executable.
I've tried using
pyinstaller myscript.py
and
pyinstaller --onefile myscript.py
to create the .exe file, however both times I've tried the .exe after it has been created, it's produced this error or a very similar error:
[4129] Error loading Python lib
'/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python':
dlopen:
dlopen(/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python,
10): no suitable image found. Did find:
/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python:
code signature invalid for
'/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python'
The script I'm trying to run doesn't involve any images but it uses selenium webdriver, I'm very new to python so I don't know if either of these things would be a problem.
I have also tried uninstalling python3.8 and installing python3.7.9 but this has not worked either.

Pyinstaller : Kivy: AttributeError: 'NoneType' object has no attribute 'clearcolor'

I am trying to package a kivy based python application for windows using auto-py-to-exe. auto-py-to-exe uses Pyinstaller for packaging. So after packaging the application and trying to run the created executable file of the application, I encounter this error:
File "desktop.py", line 356, in <module>
AttributeError: 'NoneType' object has no attribute 'clearcolor'
which in the actual code in desktop.py refers to:
from kivy.core.window import Window
....something....
if __name__ == "__main__":
.... something
Window.clearcolor = (1, 1, 0.99, 1)
....something
Here I am trying to provide close to white color background to the window.
I have checked for proper installation of kivy and availability of kivy.core.window module in site-packages of python.
I have read at severals places to use the package-name in --hidden-import as sometimes modules may not be picked due incorrect path or other issues, so I have tried passing this module as --hidden-import "kivy.core.window" and also tried --add-data flag as --add-data "C:/Python3/Lib/site-packages/kivy/core/window;window/" to forcefully include kivy.core.window.
However no luck and I still getting the same error.
If I am not mistaken the above mentioned error means the code get Nonetype when it tries to access window although the module is present at right place i.e. after packaging it is present in the package along with other kivy modules.
Also when I run the script from some IDE it works fine.
I have followed this document for debugging the Pyinstaller warnings/errors.
Config: Windows10, Python3.4, kivy 1.11.1
What am I missing or how can I specify executable to look for the file at the correct path?
So after #inclement's comment : to remove the line
After removing this line I get [CRITICAL] [App ] Unable to get a Window, abort. . I have browsed this error and found different solution referring to sdl2.dll here. So I went ahead and added path to .dll files for sdl2, glew and angle in Windows environment variable path PATH = C:\Python3\share\sdl2\bin and so on for glew and angle. So all the .dll files are imported properly and it works fine.
I use this way to solve it:
(If you don't want to find sdl2 bin path, you can use this way.)
pip install pygame
If you use custom spec, you will need to edit it to let pyinstaller rebuild exe.
I don't know how does it work, but it work for me.
(Pygame also use sdl2)
(My env: kivy 2.1.0, pyinstaller 5.1, conda env, python 3.7)
Or like answer above, but use some different way:
# In spec file, modify this line:
a = Analysis(
...
binaries=[(r"Your_env_path\share\sdl2\bin\*.dll", ".")],
...
)
You can also use --add-binary argument.
how to use bundled program after pyinstaller --add-binary?
# In Unix
pyinstaller -w --add-binary="Your_env_path\share\sdl2\bin\*.dll:." -F main.py
# In Window
pyinstaller -w --add-binary="Your_env_path\share\sdl2\bin\*.dll;." -F main.py
Or following official way:
https://kivy.org/doc/stable/guide/packaging-windows.html
"Editor and add these lines at the beginning of the spec"
# In spec file:
from kivy_deps import sdl2, glew
exe = EXE(
...
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
...
)
My english is not good, hoping this conveys the correct meaning.

FatalError failed to execute script. PyQt5

I know that questions have already been raised on this topic, but I believe that all decisions were strictly individual. The essence of the problem:
There is a calculator.py script and a kalkulator.py These files are in the same directory, the calculator file is executable, this is the file that I convert into an EXE using PyInstaller. Inside the file, I import several PyQt5 libraries, and the second file is Python: from kalkulator import *
The second file kalkulator.py contains the GUI of the program created with QtDesigner
When i run the command pyinstaller --onefile --debug calculator.py everything goes fine.
But when I run the EXE program file in debug mode, I see the following error:
The photo shows that the following error occurs.
"DLL Load Failed: The specified procedure could not be found."
I can assume that the problem is that when assembling, PyInstaller does not see the file kalkulator.py it contains a graphical interface.
What can you say about this problem, how do you think you can solve it?
I use:
Python 3.5
PyQt5
PyInstaller 3.3.1
I managed to solve my problem! I changed the version of Python 3.5.0 to 3.6.0, and also reinstalled PyQt5.

Error when Converting .py to .exe with cx_freeze

I am trying to convert my .py code to .exe. I tried all the options from posts on here and on the web, and all I could up with was the error below when I used cx_Freeze, and the .exe not opening when I used pyinstaller.
can someone help with the error below or give an alternative that works?
PS: my py code is actually ipython code from my jupyter notebook, but I'm trying not to share the code source.
Finally got it working while using pyinstaller, the key was to open the .exe file from the command window to be able to see the warning, which was "Import cv2 not found" after I deleted that line(since I was not using that module) and re built it, the .exe file now works. Hope this will help someone one day

Resources