How can I link other files while using cx_freeze?

I am using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I created setup.py to create my executable and everything works fine.

When cx_Freeze starts, it moves everything to the assembly directory. I have other files that I would like to include in my directory. How can i do this? Here is my structure.

src\ setup.py janitor.py README.txt CHNAGELOG.txt helpers\ uncompress\ unRAR.exe unzip.exe 

Here is my snippet:

Customization

 ( name='Janitor', version='1.0', description='Janitor', author='John Doe', author_email='john.doe@gmail.com', url='http://www.this-page-intentionally-left-blank.org/', data_files = [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']), ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']), ('', ['README.txt']) ], executables = [ Executable\ ( 'janitor.py', #initScript ) ] ) 

I can't get this to work. Do I need a MANIFEST.in file?

+46
python distutils cx-freeze
Mar 31 '10 at 14:44
source share
4 answers

Figured it out.

 from cx_Freeze import setup,Executable includefiles = ['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 should only contain "relative paths to the setup.py script, otherwise the assembly will fail.
  • include_files can be a list of ie lines of a bunch of files with their relative paths
    or
  • include_files can be a list of tuples in which the first half of the tuple is the name of the file with the absolute path, and the second half is the name of the destination file with the absolute path.

(When there is a lack of documentation, consult Kermit the Frog)

+90
May 23 '10 at 17:31
source share

There is a more complex example at http://wiki.wxpython.org/cx_freeze The lack of documentation for all options is at http://cx-freeze.sourceforge.net/cx_Freeze.html

With Cx_Freeze, I still get assembly output from 11 files in one folder, although, unlike Py2Exe.

Alternatives: http://www.blog.pythonlibrary.org/category/packaging/

+6
Oct. 19 '11 at 9:18
source share

You can also create a separate script that will copy the files after the build. This is what I use to restore the application on windows (you must have installed "GNU Utilities for win32" to make "cp" work).

build.bat:

 cd . del build\*.* /Q python setup.py build cp -r icons build/exe.win32-2.7/ cp -r interfaces build/exe.win32-2.7/ cp -r licenses build/exe.win32-2.7/ cp -r locale build/exe.win32-2.7/ pause 
+1
Jun 08 '14 at 8:56
source share

To find attachments (include_files = [-> your attachments <-]), you must insert the following command 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) 

See cx-freeze: using data files

0
Aug 12 '16 at 11:23
source share



All Articles