r/Python • u/Extreme_Being7689 • 2d ago
Discussion pyinstall --onedir vs --onefile
Which one better? Currently I am using --onefile. But facing some tmpfs problem. What do you suggest?
Does --onefile actually shrinks the app size?
18
Upvotes
20
u/aiuniverse-3p3_here 2d ago
Bro, I also started with --onefile, same tmpfs problem lol.
--onefile looks clean because it's 1 file, but every time you run it, it unpacks everything to a temp folder, so it's slow to start.
--onedir is better for me. It's a folder, but it starts fast, and if something breaks you can see which file is missing.
--onefile doesn't really shrink size, it's almost same size, just packed into 1 file.
If you want fast startup, go with --onedir. If you want to send 1 file to a friend, use --onefile.
1
u/aayush_satna_dev 2d ago
`tmpfs` issues arise with `--onefile` because the full extracted application is too large for the default temporary file system. If you switch to `--onedir`, it would avoid that initial large extraction to a temporary location entirely.
By the way, does `tmpfs` error message give any details about available space or file sizes?
2
u/Witty_Lingonberry_24 1d ago
PyInstaller gives you two packaging options and somehow both come with their own problems lol.
2
u/blandsquad_6 2d ago
--onedir is the way to go if you're hitting tmpfs headaches, that's the classic tradeoff. --onefile dumps everything into _MEIPASS at launch so it's slower to start and any hiccup with temp space kills it.
And no, it doesn't shrink the final payload, you're still hauling the same interpreter and libs around, it's just bundled into one executable that has to unpack itself.
1
u/YuShi2714 1d ago
Both options have their advantages.
--onefile
--onedir
I would choose --onefile if convenient distribution is the priority, and --onedir if reliability and easier debugging matter more.
1
u/Minute-Age9938 9h ago
onefile doesn't shrink it. It packs the same files into one exe, then unpacks them into a temp dir every time you launch. That's the tmpfs hit: the bootloader needs a writable temp with enough space, and a lot of machines mount /tmp as a small tmpfs or with noexec. onedir leaves those files next to the exe, so startup skips that unpack and the size stays about the same. If you still want one thing to hand someone, zip the onedir folder instead of switching back to onefile.
1
u/OkCardiologist8006 2d ago
if you have to stick with onefile, --runtime-tmpdir (or just setting TMPDIR) lets you change where it unpacks, so a tiny tmpfs stops mattering. otherwise onedir and zip the folder if you want a single download
1
u/DeaD_EyE_1 2d ago
--onefile if it's not complicated and close to 0 dependencies
--onedir if you have dependencies
Onedir should have better startup times, because it isn't decompressed somewhere.
0
u/ARob20 2d ago
I believe an issue with onedir is security. Easier for someone to amend a file somewhere in a library by simply swapping it.