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?

 Answers

67

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.

setup(
         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
 
Semirix
answered 7 Months ago
94

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:

   Pmw.py has been created.
   Before running freeze, also copy the following file(s):
   C:UsersjoaquinDesktopPmw.1.3.2srcPmwPmw_1_3libPmwBlt.py
   C:UsersjoaquinDesktopPmw.1.3.2srcPmwPmw_1_3libPmwColor.py

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, 'Pmw.py', 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:
#
#    PmwBlt.py PmwColor.py

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):
            break
        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 PmwBlt.py.
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 ()
    else:
        return _VERSION

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

"""
if '-noblt' in sys.argv:
    sys.argv.remove('-noblt')
    needBlt = 0

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

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

srcdir = sys.argv[1]

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

outfile = open('Pmw.py', 'w')

if needColor:
    outfile.write(colorCode)

if needBlt:
    outfile.write(bltCode)

outfile.write(extraCode % version)

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

files.append('LogicalFont')
for file in files:
    text = mungeFile(file)
    outfile.write(text)

print ''
print '   Pmw.py has been created.'

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

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
 
Averroes
answered 3 Months ago
67

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

the setup.py must be edited. the missing_dlls list must be:

missing_dll = ['libgtk-3-0.dll',
           'libgdk-3-0.dll',
           'libatk-1.0-0.dll',
           'libcairo-2.dll',
           'libcairo-gobject-2.dll',
           'libgdk_pixbuf-2.0-0.dll',
           'libjpeg-8.dll',
           'libpango-1.0-0.dll',
           'libpangocairo-1.0-0.dll',
           'libpangoft2-1.0-0.dll',
           'libpangowin32-1.0-0.dll',
           'libgirepository-1.0-1.dll',
           'libffi-6.dll',
           'libfontconfig-1.dll',
           'libfreetype-6.dll',
           'libgio-2.0-0.dll',
           'libglib-2.0-0.dll',
           'libgmodule-2.0-0.dll',
           'libgobject-2.0-0.dll',
           'libpng15-15.dll',
           'libpyglib-gi-2.0-python-0.dll',
           'libxml2-2.dll',
           'zlib1.dll',
           'libgnutls-26.dll',
           'librsvg-2-2.dll',
           'libgcrypt-11.dll',
           'libp11-kit-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',
            'lib/girepository-1.0',
            'share/glib-2.0',
            'share/gtk-3.0']

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

Tuesday, October 5, 2021
 
Sujith
answered 2 Months ago
35

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()
master.title("Points")
w = Canvas(master,
           width=canvas_width,
           height=canvas_height)
w.pack(expand=YES, fill=BOTH)
w.bind("<B1-Motion>", paint)

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

mainloop()
Friday, November 5, 2021
 
user1882705
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 :  
Share