pyinstaller exe without any dependencies?

2019-07-30 23:29发布

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.

2条回答
The star\"
2楼-- · 2019-07-31 00:00

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.

查看更多
我想做一个坏孩纸
3楼-- · 2019-07-31 00:20

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

查看更多
登录 后发表回答