cx_Freeze python single file?

Question:

I’ve been using cx_Freeze for a while now and there is one thing I’ve really wanted to do: put ALL files into ONE executable that I can distribute. It’s not really user-friendly to send around a folder filled with 30 files, all in the same directory. How can I accomplish this?
Thanks.

Asked By: pajm

||

Answers:

Isn’t this what bbfreeze does?

Tutorial here: http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/

It’s actually not that hard to roll your own with Python zipimport http://docs.python.org/library/zipimport.html

You may prefer to use something like UPX which is a more general solution, not Python only. http://upx.sourceforge.net/

Answered By: Michael Dillon

It is not supported in cx_freeze. There was discussion about it on mailing list. As I recall, the author stated that others (PyInstaller, Py2Exe) use some dirty hacks to achieve that. Some anti-virus programs can consider that behavior as a virus also.

I used PyInstaller for some time, but went back to cx_freeze because of Python 2.7 support. I pack everything using Inno Setup, so it is easy to distribute. Depends if you use Windows or not.

Answered By: Fenikso

You can use ‘bdist_msi’ instead of ‘build’. This will create a dist folder in the directory with a single setup application.

http://cx-freeze.readthedocs.io/en/latest/distutils.html

Answered By: Quazi R

According to the documentation

cx_Freeze does not support building a single file exe, where all of the libraries for your application are embedded in one executable file.

The documentation gives some options to obtain a single file.

A further option under Windows is to use the bdist_msi command to create a single Microsoft Installer file (.msi) for your application, as mentioned by @QuaziRabbi. This command has few cx_Freeze-specific options documented here to customize the installer. This command overloads the bdist_msi command of the distutils package which itself brings some more options to customize the installer. The available options are not documented, one need to look at the source code of the distutils package. Interesting examples are Use cx-freeze to create an msi that adds a shortcut to the desktop and cx_freeze bdist_msi: create registry entries?

Another option is to use another tool to create a more customizable single-file installer for the frozen application after the cx_Freeze build step. The script-based tool NSIS (Nullsoft Scriptable Install System) allows one to create a very customizable installer and the use of a script means that this step can be completely automatized. @Fenisko’s answers mentions another tool, and there are many more.

Answered By: jpeg
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.