error in creating executable for python script - python

I have created a application using python2.7 also used pyqt for gui. I have also used pybel module for computations.
my application python file works properly. but when I try to create executable from that python file it gives me error.
I have tried using py2eye, cx_freeze and pyinstaller too.
I am wondering if the python file runs well after typing "python ui_MolecularTest.py" on command prompt, why I am unable to create executable from the same?
Thanks

Related

Packing python scripts into .exe file while keeping imported modules

I have a python script I want to pack into .exe file for the ease of use. The python script makes extensive use of Tkinter module for nice GUI. I've packed it first into .exe using pyinstaller and the guide outlied here - https://datatofish.com/executable-pyinstaller/
I have two problems. First is that my script makes use of FlowCal module, which doesn't come with Python's pyinstaller (I've made script using Spyder, and I'm using Python 3.8. to compile using pyinstaller) - so I installed FlowCal with pip install FlowCal so Python gets it too (I think that's how it works? Not too sure). But then FlowCal is dependent on various sklearn modules, and it would be a headache to install modules, compile to exe, then check if it works over and over. Is there a way that ALL modules script uses (and ALL modules that imported modules use) are compiled into the script?
Second problem is that alongside GUI I get another window. Picture included. How do I remove that window?
Another thing you can do without any hassle is using auto-py-to-exe. This will generate .exe from .py with writing command, just clicking some buttons in a GUI. For this, you have to give the command: pip install auto-py-to-exe in command prompt or PowerShell, whatever you like most. After successfully installing auto-py-to-exe, give the command auto-py-to-exe in your command prompt. Then give the necessary informations, and get your generated executable file!
Add the missing modules to the hiddenimports
hiddenimports=['sklearn.neighbors.typedefs','sklearn.neighbors.quad_tree','sklearn.tree._utils']
Or use it when you create the exe in cmd as
--hidden-import=modulename

Pyinstaller does not create functional executable with pdfrw

I'm trying to create an executable file using pyinstaller, but it crashes immediately upon launching that executable. It should be noted that the program works perfectly fine inside of PyCharm. I've narrowed it down to only one line of code that causes it to error using another python file - if the file contains
'''import pdfrw'''
it will crash immediately upon launching the executable file created by pyinstaller.
I've tried the following commands from a command prompt running in administrator mode, all of which give that same result (this is after changing the directory to where the .py file is located):
pyinstaller "compiling test.py"
pyinstaller --onefile "compiling test.py"
pyinstaller --onedir "compiling test.py"
Using a try/except clause around the import statement, I'm able to see the error message before it closes the executable, and it says:
Cannot load native module 'Crypto.Cipher._raw_ecb': Trying '_raw_ecb.cp36-win_amd64.pyd': cannot load library 'C:\Users\KYLE~1.AFF\AppData\Local\Temp_MEI534042\Crypto\Util..\Cipher_raw_ecb.cp36-win_amd64.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\Users\KYLE~1.AFF\AppData\Local\Temp\_MEI534042\Crypto\Util\..\Cipher\_raw_ecb.cp36-win_amd64.pyd', Trying '_raw_ecb.pyd': cannot load library 'C:\Users\KYLE~1.AFF\AppData\Local\Temp_MEI534042\Crypto\Util..\Cipher_raw_ecb.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\Users\KYLE~1.AFF\AppData\Local\Temp\_MEI534042\Crypto\Util\..\Cipher\_raw_ecb.pyd'
Is there a way I can modify the spec file to make the file correctly (or another solution)? I found something similar when I needed to make an executable with python-docx (and I will most likely need to do this for this program as well, as the original python program I'm trying to make an executable uses python-docx as well as pdfrw): PyInstaller and python-docx module do not work together
Thanks for your help in advance.
So I just found a solution to this! It tipped me off when it was going down a user path named \KYLE~1.AFF\ because that user shouldn't exist, though somehow it got created. After removing that user file, I upgraded pyinstaller via pip install --upgrade pyinstaller, and it uninstalled version 3.3.1, and installed version 3.6, and now it works fine. So possibly it was the new version, but I'm guessing it was more likely the fresh install after I removed the user directory that shouldn't have existed. Not sure why it only errored out with that one library though.

Pyinstaller can't find module TkTreeCtrl

I have a program that makes use of the MultiListView from TkTreeCtrl which I'm trying to compile into an executable file using pyinstaller. I'm able to create the executable file and run it, however as soon as it gets to the initialization of the MultiListView it throws up a window that says "Failed to execute script app". How can I get pyinstaller to recognize MultiListView? TkTreeCtrl is unable to be installed via pip, it required putting the folder in my directory and running setup.py.
I've tried searching for a "hook" file online to allow pyinstaller to find the module, I can't seem to find one. I've also tried --hidden-import=tkinter as I've seen that suggested but can't decipher what it's supposed to do. It does the same thing with or without being compiled as a single file. I used a logger and guaranteed that it's on the line where the MultiListBox is created that the program crashes. If it needs stating, I can launch the python file using the command line just fine on my computer.
I use pyinstaller --onefile --windowed Scripts/JobMaintainer/app.py in Command Line to compile the program
Expected: A Google search would result in a hook file that I could attach to my pyinstall which would allow TkTreeCtrl to be added to my executable file
Actual: Until I find some sort of solution, TkTreeCtrl causes it to be impossible to create an executable file from a python script.

Issue in converting python file to an executable using cx_freeze

I have been working on a python GUI based project using PyQt5. I am done with that and it runs perfectly on my PC but I want to make an executable out of it. So, i'm using cx_freeze to convert my python file to an executable. I have python version 3.5 and PyQt5.
When I build the script the build folder is made and when I run the executable it get the missing modules error as shown in the image attached.
Kindly, help me out i am stuck on this for ages now.
Copy all the modules in the same directory as the file you are converting to exe, then try it again.

Creating an executable from python script

I'm trying to create a standalone executable file from python script using py2exe (following instructions at link ). When I run the setup.py from cmd, it shows an error saying "no module named urllib", although urllib is a builtin module. Please help out.

Categories

Resources