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.
Related
py file in which I am executing a .exe file created in C++ (is inside a "data" folder)
Python Code:
os.system("data\\time.exe")
When I use the pyinstaller with the --onefile attribute I can't find a way for my program to compile the .py file + the "data" with another .exe inside.
Does anyone know how to convert my entire program into a single .exe? in which I can run my python program and also my .exe from C++ inside?
(I have tried to test with the .spec and with the --add-data attribute but I can't find a way that is compatible with what I want to do)
I look forward to your response,
Thanks you very much <3
There is a program called auto-py-to-exe which creates an exe out of your program without requiring you to create a setup file. The interface is great and allows you to easily create and exe without creating a setup.py. This also allows you to package your app as a single exe, without any other files. Below is a screenshot:
You can install the program by typing into the command line:
python -m pip install auto-py-to-exe
You can run it by typing in:
auto-py-to-exe
To see more about auto-py-to-exe, please visit the PyPI page at https://pypi.org/project/auto-py-to-exe/.
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
I'm trying to run pyinstaller in python exe file in order to someone without python can use pyinstaller but no idea how to do it.
I tried import PyInstaller with other needed modules and convert this script to exe but I got error "The 'PyInstaller' distribution was not found and is required by the application". I also tried to pack PyInstaller exe file but didn't worked too. Python 3.6.5
Any ideas how to do it?
Unfortunately, what you're describing is not possible with PyInstaller. I submitted an issue on GitHub, and this is what one of the developers said:
Nope, this won't work.
PyInstaller internally uses a lot of sub-processes where it is assumed that sys.executable points to a python interpreter (e.g., here); this is not true in a frozen application, where it points to the frozen executable, which ends up in effectively endless recursion.
Even if this was not a problem, the frozen application includes only a subset of python environment, so it cannot be used to freeze an arbitrary script (not to mention the issue of 3rd party packages).
So whatever use case you have for this, it cannot be supported by PyInstaller.
check the requirements for the Pyinstaller from this link initially
https://pythonhosted.org/PyInstaller/requirements.html
Then install Pyinstaller by,
pip install pyinstaller
To create .exe file use this command for basically,
pyinstaller your_script.py
To run the created .exe
METHOD 1
Do double click the .exe file in your directory.
METHOD 2
In your cmd prompt load in to your current directory or project directory then do
: .\dist\your_script.exe
because the create .exe files are saved in dist folder inside to the project folder with the name of your script file names only.
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.
I am trying to create an .exe file such that when run on any windows 10 pc will run without requiring any installations. What I tried using was:
pyinstaller --onefile main.py
I ran the exe file on a friend's computer and it turns out that it required first python2.7 to be installed, then it said that modules weren't installed i.e; no module named datetime found. The executable finally ran after I installed all dependencies on my friend's computer but the whole point of creating .exe file was useless, I might as well have just typed python main.py after doing so much. Is there an appropriate way I could get an .exe file from .py which wont require anything to be installed? Like an actual standalone app. Thank you!
Actually this should work. I never had problems with pyinstaller, yet. Maybe reinstall pyinstaller or make sure to use the newest version. Also try first of all an easy "helloWorld"
input("hello from Console.\nPress Enter to close it :)")
Just tried this one on a colleague's machine that has no python installed. And it worked well.
I've had good results using the pyinstaller module to one file even when running code with multiple dependencies on machines without python installed. Reading the documentation helped There is a comprehensive list of python to exe compilers in another stackoverflow question: a good python to exe compiler?