So I'm using pyinstaller with python27, and my exe works great so long as it's in the same directory as the build folder. I need it to be a completely standalone exe, without any dependencies, is there a way to bundle the important things from the build folder into one file? Neither -F nor --onefile seems to do this.
Edit: as I explain in my answer below, I thought pyinstaller was the problem because the exe would only run in the dist folder, so I assumed it had dependencies there, but in reality, it was running and then instantly crashing due to a bug that only triggered when the exe was on the desktop.
I figured out that the reason it wasn't working had nothing to do with pyinstaller or dlls. The exe was opening, and and trying to input powershell commands via python like it was supposed to. Unfortunately I had a line of code that said this:
the problem was that sys.argv[0] changed when I put the exe on the desktop, and ended up being a path that looked like C://Users/John Smith/Desktop. The space in between John and Smith made powershell mad and crashed the program, so I escaped it using this line of code:
and then I replaced sys.argv[0] with my new path variable. Hope this helps anyone in the future trying to do the same thing.
after
pyinstaller
has converted your script into.exe
, than you need to add theexecutable
topath
, otherwise you have to open thecommand line
in the directory that the file is in.pyinstaller
just puts yourscript
andpy interpretor
into a single file. same goes for linux.for dependency side, look here.
there are other options you can try to bbFreeze, py2exe, cx_Freeze
to use pyinstaller in a simple way:
now you should see couple of files build, dist(
exe
in here).NOTE: that
--onefile
flag doesn't necessarily get rid of the need for it to have link with certain libraries, it will still need those in order to run.prepare for distribution, first need to get a spec file:
to get a spec file: pyinstaller --noconsole your_file.py
than you can get the exe file for distribution like so:
for more info and tutorial look here
see if nuitka works for you, it might sound scary but it is not. it compiles your code to executable binary format. Be aware that under the hood first it converts to c++ API calls.
if you dont like that for closed source program use
Cython
, and for no dependency usepy2exe