r/Python • u/Extreme_Being7689 • 3d 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?
1
u/aayush_satna_dev 3d 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/Extreme_Being7689 3d ago
one of the user of my app reported that he sees 3gb+ tmps data. He probably opened and closed the app without restarting system 20+ times to fill up the /run/user/1000. I will be switching to --onedir to get out from this mess
1
u/aayush_satna_dev 3d ago
There you go. Also, ensure that --onefile app doesn't get force killed else PyInstaller's bootloader will never clean up the tmp folders
2
u/Witty_Lingonberry_24 2d ago
PyInstaller gives you two packaging options and somehow both come with their own problems lol.
2
u/blandsquad_6 3d 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
Easier to distribute because everything is packed into one executable.
Usually has a slower startup because files are extracted at launch.
Can sometimes trigger antivirus false positives.
--onedir
Usually starts faster.
Easier to debug and troubleshoot.
Keeps dependencies in a separate folder, which can be more convenient for larger applications.
I would choose --onefile if convenient distribution is the priority, and --onedir if reliability and easier debugging matter more.
1
u/Minute-Age9938 23h 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 3d 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 3d ago
I believe an issue with onedir is security. Easier for someone to amend a file somewhere in a library by simply swapping it.
6
21
u/aiuniverse-3p3_here 3d 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.