Asked  7 Months ago    Answers:  5   Viewed   107 times

I am using cx_freeze to deploy my application. I would like to include a entire directory since including individual files doesn't put them in a folder. How can I include a folder?



You have to set up an include files argument for the building options. You can do this in different ways, but I will show a part of my configuration. The thing I describe here is for one specific file and one specific destination. I think you can also set a path like this, but I don't have tested this yet.

Edit: Tested this, so choose the right approach for your project.

buildOptions = dict(include_files = [(absolute_path_to_your_file,'final_filename')]) #single file, absolute path.

buildOptions = dict(include_files = ['your_folder/']) #folder,relative path. Use tuple like in the single file to set a absolute path.

         name = "appname",
         version = "1.0",
         description = "description",
         author = "your name",
         options = dict(build_exe = buildOptions),
         executables = executables)

Take also a look at this topic. It adressed propably the same question: How can i bundle other files when using cx_freeze?

Tuesday, June 1, 2021
answered 7 Months ago

Unfortunately, the original file has some problems with tabs and spaces (just look at the while indentation in expandlinks).

I fixed those indentation problems, changed regsub.gsub with re.sub and eliminated the string import, using the string type methods.

After that the script worked perfect: has been created.
   Before running freeze, also copy the following file(s):

Here you have the corrected script:

#!/usr/bin/env python

# Helper script when freezing Pmw applications.  It concatenates all
# Pmw megawidget files into a single file, '', in the current
# directory.  The script must be called with one argument, being the
# path to the 'lib' directory of the required version of Pmw.
# To freeze a Pmw application, you will also need to copy the
# following files to the application directory before freezing:

import os
import re
import sys

# The order of these files is significant.  Files which reference
# other files must appear later.  Files may be deleted if they are not
# used.
files = [
    'Dialog', 'TimeFuncs', 'Balloon', 'ButtonBox', 'EntryField',
    'Group', 'LabeledWidget', 'MainMenuBar', 'MenuBar', 'MessageBar',
    'MessageDialog', 'NoteBook', 'OptionMenu', 'PanedWidget', 'PromptDialog',
    'RadioSelect', 'ScrolledCanvas', 'ScrolledField', 'ScrolledFrame',
    'ScrolledListBox', 'ScrolledText', 'HistoryText', 'SelectionDialog',
    'TextDialog', 'TimeCounter', 'AboutDialog', 'ComboBox', 'ComboBoxDialog',
    'Counter', 'CounterDialog',

# Set this to 0 if you do not use any of the Pmw.Color functions:
needColor = 1

# Set this to 0 if you do not use any of the Pmw.Blt functions:
needBlt = 1

def expandLinks(path):
    if not os.path.isabs(path):
        path = os.path.join(os.getcwd(), path)
    while 1:
        if not os.path.islink(path):
        dir = os.path.dirname(path)
        path = os.path.join(dir, os.readlink(path))

    return path

def mungeFile(file):
    # Read the file and modify it so that it can be bundled with the
    # other Pmw files.
    file = 'Pmw' + file + '.py'
    text = open(os.path.join(srcdir, file)).read()
    text = re.sub('import Pmw>', '', text)
    text = re.sub('INITOPT = Pmw.INITOPT', '', text)
    text = re.sub('<Pmw.', '', text)
    text = 'n' + ('#' * 70) + 'n' + '### File: ' + file + 'n' + text
    return text

# Work out which version is being bundled.
file = sys.argv[0]
file = os.path.normpath(file)
file = expandLinks(file)

dir = os.path.dirname(file)
dir = expandLinks(dir)
dir = os.path.dirname(dir)
dir = expandLinks(dir)
dir = os.path.basename(dir)

version = dir[4:].replace('_', '.')

# Code to import the Color module.
colorCode = """
import PmwColor
Color = PmwColor
del PmwColor
# Code to import the Blt module.
bltCode = """
import PmwBlt
Blt = PmwBlt
del PmwBlt
# Code used when not linking with
ignoreBltCode = """
_bltImported = 1
_bltbusyOK = 0
# Code to define the functions normally supplied by the dynamic loader.
extraCode = """

### Loader functions:

_VERSION = '%s'

def setversion(version):
    if version != _VERSION:
        raise ValueError, 'Dynamic versioning not available'

def setalphaversions(*alpha_versions):
    if alpha_versions != ():
        raise ValueError, 'Dynamic versioning not available'

def version(alpha = 0):
    if alpha:
        return ()
        return _VERSION

def installedversions(alpha = 0):
    if alpha:
        return ()
        return (_VERSION,)

if '-noblt' in sys.argv:
    needBlt = 0

if '-nocolor' in sys.argv:
    needColor = 0

if len(sys.argv) != 2:
    print 'usage: [-noblt] [-nocolor] /path/to/Pmw/Pmw_X_X_X/lib'

srcdir = sys.argv[1]

if os.path.exists(''):
    print ' already exists. Remove it and try again.'

outfile = open('', 'w')

if needColor:

if needBlt:

outfile.write(extraCode % version)

# Specially handle file:
text = mungeFile('Base')
text = re.sub('import PmwLogicalFont', '', text)
text = re.sub('PmwLogicalFont._font_initialise', '_font_initialise', text)
if not needBlt:

for file in files:
    text = mungeFile(file)

print ''
print ' has been created.'

if needColor or needBlt:
    print '   Before running freeze, also copy the following file(s):'
    if needBlt:
        print '   ' + os.path.join(srcdir, '')
    if needColor:
        print '   ' + os.path.join(srcdir, '')
Friday, August 6, 2021
answered 4 Months ago

i=0; for f in *; do d=dir_$(printf %03d $((i/100+1))); mkdir -p $d; mv "$f" $d; let i++; done

Monday, September 6, 2021
answered 3 Months ago

I have manualy tried what DLLs are required. So if this will help someone:

the must be edited. the missing_dlls list must be:

missing_dll = ['libgtk-3-0.dll',

and when you dont want all the files from share, etc and lib, edit the gtk_libs list:

gtk_libs = ['lib/gdk-pixbuf-2.0',

you might include also the lib/engines, but I dont needed it.

Tuesday, October 5, 2021
answered 2 Months ago

There is no method to directly put a point on Canvas. The method below shows points using create_oval method.

Try this:

from Tkinter import *

canvas_width = 500
canvas_height = 150

def paint(event):
    python_green = "#476042"
    x1, y1 = (event.x - 1), (event.y - 1)
    x2, y2 = (event.x + 1), (event.y + 1)
    w.create_oval(x1, y1, x2, y2, fill=python_green)

master = Tk()
w = Canvas(master,
w.pack(expand=YES, fill=BOTH)
w.bind("<B1-Motion>", paint)

message = Label(master, text="Press and Drag the mouse to draw")

Friday, November 5, 2021
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :