How can I bundle other files when using cx_freeze?
Figured it out.
from cx_Freeze import setup,Executableincludefiles = ['README.txt', 'CHANGELOG.txt', 'helpers\uncompress\unRAR.exe', , 'helpers\uncompress\unzip.exe']includes = []excludes = ['Tkinter']packages = ['do','khh']setup( name = 'myapp', version = '0.1', description = 'A general enhancement utility', author = 'lenin', author_email = 'le...@null.com', options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}}, executables = [Executable('janitor.py')])
Note:
include_files
must contain "only" relative paths to thesetup.py
script else the build will fail.include_files
can be a list of string i.e a bunch of files with their relative paths
orinclude_files
can be a list of tuples in which the first half of the tuple is the file name with the absolute path and the second half is the destination filename with the absolute path.
(When the lack of the documentation arises, consult Kermit the Frog)
There's a more complex example at: cx_freeze - wxPyWiki
The lacking documentation of all the options is at: cx_Freeze (Internet Archive)
With cx_Freeze
, I still get a build output of 11 files in a single folder, though, unlike with Py2Exe
.
Alternatives: Packaging | The Mouse Vs. Python
In order to find your attached files (include_files = [-> your attached files <-]
) you should insert the following function in your setup.py code:
def find_data_file(filename): if getattr(sys, 'frozen', False): # The application is frozen datadir = os.path.dirname(sys.executable) else: # The application is not frozen # Change this bit to match where you store your data files: datadir = os.path.dirname(__file__) return os.path.join(datadir, filename)