Error when Converting .py to .exe with cx_freeze - python-3.x

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

Related

Unable to read downloaded file after converting python file to .exe

I have written some code in python with the help of selenium which is doing web crawling in which it goes to a website after entering login id and password and downloaded a file. I have written the code in jupyter notebook with file name as GSPL_Code.ipynb and with the use of !jupyter nbconvert --to script GSPL_Code.ipynb and !pyinstaller GSPL_Code.py, I have first converted .ipynb file to .py and then made a .exe file from the .py file.
If I run the .exe file which is named as GSPL_Code and it is stored in dist/GSPL_Code then a file crv_report.xlsx is downloaded in the dist/GSPL_Code folder where the executable file is also there but the problem is code does not executed after downloading a file in that location. It got stuck. Nothing is happening now. When I run in jupyter notebook then I don't face any problem but after converting it into .exe, I am facing the problem.
Please find the following python code which is part of the whole script:
def handler(driver):
curr=driver.current_window_handle
for handle in driver.window_handles:
driver.switch_to.window(handle)
if handle != curr:
driver.close()
for handle in driver.window_handles:
driver.switch_to.window(handle)
print(driver.current_url)
click_event('//img[#id="IconImg_crv_report_toptoolbar_export"]')
click_event('//div[#style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:249px"]')
click_event('//span[#title="Microsoft Excel Workbook Data-only"]')
sleep(5)
click_event('//td[#class="wizbutton"]')
sleep(15)
print("Report is downloaded")
PATH1="C:\\Users\\ankit19.gupta\\Desktop\\Test_GSPL\\dist\\GSPL_Code"
crv_report= "/crv_report.xlsx"
print("Reading File")
dataframe1 = pd.read_excel(PATH1+crv_report)
print("Data is stored in the dataframe")
return dataframe1
I have written some print statements to see where the error is coming. So, here I am unable to see the print statement "Report is downloaded". Before this click_event('//td[#class="wizbutton"]') is used to click a button which download the file in chrome browser and I can see this downloaded file in the path dist/GSPL_Code directory and it got executed successfully but after that it got stuck and nothing happened.
I am unable to find what is happening here. Can anyone please help me. Any help would be appreciated.
Edit: There were some delay due to which print statements "Report is not downloaded" and "Reading File" were not showing in console but now I am able to see it but it is unable to read the file crv_report which is on the path PATH1 and it got stuck here and due to which I am unable to see print statement Data is stored in the dataframe
I think code is unable to access the file because os.remove is also not working when I try to delete the crv_report file. Can anyone please help me.
OS Directory Change:
When refactoring python files, in your case changing .py to .exe, it's important to make sure everything is a part of the current working directory. Simple OS checker command:
cwd = os.getcwd()
If directories are misaligned, you will need to run an OS command to change the directory before interacting with any files:
os.chdir('/your/desired/directory')

Issue making .exe with Pyinstaller : compilation is done but the .exe fails

I have a rather large python script that I would like to convert to .exe. I use PyInstaller and I managed to import every library needed so now I don't get any error message. My problem is that at some point, the .exe is stuck, so the conversion with PyInstaller didn't really worked. I suspect the issue is related to the PyAutoGui library, but I had to import it to convert my python script (I used pip install).
Does anyone else got the same issue? Is there something I can do to remove this issue?
I have python 3.9.2 and pyinstaller 4.2 and I am working with windows 10.
The libraries I had to import are : pyautogui, pandas, bs4, pygame, PyQt5, pywin32, winshell, pymysql, sqlalchemy, sqlalchemy.sql.default_comparator, wmi, Pillow, psutil and lxml.
Thanks for your suggestions!
In my experience, PyInstaller has had trouble generating .exe files from python scripts that use graphics libraries such as pygame and PyQt5. Mostly, it fails to generate the .exe and even when it does, the .exe takes a long time to load up and is really slow. If you want an .exe file, I would suggest trying out cx_freeze. To my knowledge, it won't generate .exe in one file like pyinstaller does, but the .exe file it does generate is of much higher quality.
We think we found the issue: pyautogui needs an other package called open-cv to work. Hope it'll help someone someday ;-)

TkDnd working in Spyder but gives error after converting .exe

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

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.

Cannot find module _frozen_importlib_external when running a frozen exe program

Hi I am pretty new to cx_Freeze, so when I try to freeze a Python file (it's just a basic hello world program) cx_Freeze creates an exe along with a bunch of other things. When I run the exe it gives me a "cannot find module _frozen_importlib_external" error. I am using Python 3.5 and running Windows 10. Any help is greatly appreciated. Thanks.
I had the same problem.
The issue here is that cx_freeze can't see the import and will not embed the package _frozen_importlib_external.
Change the file cx_Freeze/finder.py with the diff given at https://bitbucket.org/anthony_tuininga/cx_freeze/pull-requests/83/python-35-compatibility-for-cx_freeze-4x/diff and then build and install cx_Freeze again.

Resources