Should I use PyInstaller onefile or onedir, and does onefile save space?

November 21, 2026 4 answers
Asked by _k93~zeldravi.4

I'm using PyInstaller's onefile mode and running into temporary filesystem problems. Would onedir be a better choice? Does onefile actually make the application smaller?

Answers

Ruvzelo+9c

I'd try onedir for this. Onefile extracts its bundled files to a temporary directory each time it starts, so limited temporary space can stop it from launching. That extraction also adds startup time.

Onedir keeps the files in a distribution folder instead. It's less tidy to hand over, but it avoids that startup extraction, and you can inspect the bundled files if something is missing.

Reply to this answer
Tavzexo.5q

Onefile gives you one executable, not necessarily a smaller app. You still need to bundle the Python interpreter and dependencies. Compression and packaging overhead can change the exact size, so compare builds of your own app rather than assuming onefile will be smaller.

Reply to this answer
7n~brindlepocket_294

If the single executable matters, you don't have to abandon it immediately. PyInstaller's --runtime-tmpdir option can set the extraction location. Depending on the environment, setting TMPDIR may also let you use a location with more space.

That still leaves the extraction step at startup, though. For a single download without that behavior, you could distribute an archive of the onedir folder.

8x!cobblewrench_641:

Make sure the chosen location has enough space and is suitable for running the extracted files.

Reply to this answer
9t!brackenlatch_582

There is a security consideration with onedir: someone with write access to the distribution folder may be able to replace bundled files. But putting everything in one executable isn't a security boundary by itself. Either way, think about who can modify the deployed app.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions