2

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.

user3150635
  • 509
  • 2
  • 9
  • 26

2 Answers2

1

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:

subprocess.check_output('schtasks /create /sc minute /mo ' + str(time) + ' /tn "test_process_to_run_every_'+str(time)+'_min" /tr //'+sys.argv[0],shell=True)
#set this exe to run every X minutes in windows scheduled tasks

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:

path = sys.argv[0].replace(" ","^")

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.

user3150635
  • 509
  • 2
  • 9
  • 26
0

after pyinstaller has converted your script into .exe, than you need to add the executable to path, otherwise you have to open the command line in the directory that the file is in. pyinstaller just puts your script and py 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:

pyinstaller --onefile your_file.py

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:

pyinstaller your_file.spec

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 use py2exe

BlooB
  • 955
  • 10
  • 23
  • so it's not possible to bundle the dependencies in pyinstaller? All it does is combine the script and the interpreter? – user3150635 Aug 15 '17 at 16:09
  • no it can http://pyinstaller.readthedocs.io/en/stable/operating-mode.html – BlooB Aug 15 '17 at 16:14
  • so the thing is, pyinstaller will look at all the import statements, however if there are things that it misses you can add additional files on the pyinstaller, or additional import paths – BlooB Aug 15 '17 at 16:16
  • try py2exe, i think that might be easier to work with – BlooB Aug 15 '17 at 16:20
  • I just read the documentation you posted, and it looks like "bundling to one file" is exactly what I want to do, but the docs don't show any sample code for how to do that. If you know how to bundle to one file, could you post it as an answer? – user3150635 Aug 15 '17 at 16:28
  • keep in mind the most pyinstaller can do, is to create a zip file that holds dependencies and stuff, which it gets extracted when someone runs .exe, i dont believe it can simply give you a single .exe file that you can move around. – BlooB Aug 15 '17 at 16:44
  • oh, then is there something that can? That's what I'm trying to do. – user3150635 Aug 15 '17 at 16:47
  • for closed source program use Cython, and for no dependency use py2exe – BlooB Aug 15 '17 at 17:06