exe - Python Pmw and cx_Freeze? -


i unable make executable python program uses pmw (python mega widgets). use cx_freeze (through gui backend "gui2exe"). searching pmw site i've found it's caused how pmw library checks modules when ran , doesn't work when use py2exe or similar programs because libraries in zip file. more info can found here: http://pmw.sourceforge.net/doc/dynamicloader.html give solution in page, under "freezing pmw", providing script generates single standalone pmw module can freeze. however, script uses deprecated code , won't work python 2.6 +. i've tried modify no luck.

edit: i'd mention replacing 'regex' 're' won't work.

#!/usr/bin/env python  # helper script when freezing pmw applications.  concatenates # pmw megawidget files single file, 'pmw.py', in current # directory.  script must called 1 argument, being # path 'lib' directory of required version of pmw. # freeze pmw application, need copy # following files application directory before freezing: # #    pmwblt.py pmwcolor.py  import os import regsub import string import sys  # order of these files significant.  files reference # other files must appear later.  files may deleted if 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 0 if not use of pmw.color functions: needcolor = 1  # set 0 if not use of 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 file , modify can bundled     # other pmw files.     file = 'pmw' + file + '.py'     text = open(os.path.join(srcdir, file)).read()     text = regsub.gsub('import pmw\>', '', text)     text = regsub.gsub('initopt = pmw.initopt', '', text)     text = regsub.gsub('\<pmw\.', '', text)     text = '\n' + ('#' * 70) + '\n' + '### file: ' + file + '\n' + text     return text  # work out version 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 = string.replace(dir[4:], '_', '.')  # code import color module. colorcode = """ import pmwcolor color = pmwcolor del pmwcolor """  # code import blt module. bltcode = """ import pmwblt blt = pmwblt del pmwblt """  # code used when not linking pmwblt.py. ignorebltcode = """ _bltimported = 1 _bltbusyok = 0 """  # code define functions supplied 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 exists. remove , 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 = regsub.gsub('import pmwlogicalfont', '', text) text = regsub.gsub('pmwlogicalfont._font_initialise', '_font_initialise', text) outfile.write(text) if not needblt:     outfile.write(ignorebltcode)  files.append('logicalfont') file in files:     text = mungefile(file)     outfile.write(text)  print '' print '   pmw.py has been created.'  if needcolor or needblt:     print '   before running freeze, copy following file(s):'     if needblt:     print '   ' + os.path.join(srcdir, 'pmwblt.py')     if needcolor:     print '   ' + os.path.join(srcdir, 'pmwcolor.py') 

unfortunately, original file has problems tabs , spaces (just @ while indentation in expandlinks).

i fixed indentation problems, changed regsub.gsub re.sub , eliminated string import, using string type methods.

after script worked perfect:

   pmw.py has been created.    before running freeze, copy following file(s):    c:\users\joaquin\desktop\pmw.1.3.2\src\pmw\pmw_1_3\lib\pmwblt.py    c:\users\joaquin\desktop\pmw.1.3.2\src\pmw\pmw_1_3\lib\pmwcolor.py 

here have corrected script:

#!/usr/bin/env python  # helper script when freezing pmw applications.  concatenates # pmw megawidget files single file, 'pmw.py', in current # directory.  script must called 1 argument, being # path 'lib' directory of required version of pmw. # freeze pmw application, need copy # following files application directory before freezing: # #    pmwblt.py pmwcolor.py  import os import re import sys  # order of these files significant.  files reference # other files must appear later.  files may deleted if 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 0 if not use of pmw.color functions: needcolor = 1  # set 0 if not use of 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 file , modify can bundled     # 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 version 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 import color module. colorcode = """ import pmwcolor color = pmwcolor del pmwcolor """ # code import blt module. bltcode = """ import pmwblt blt = pmwblt del pmwblt """ # code used when not linking pmwblt.py. ignorebltcode = """ _bltimported = 1 _bltbusyok = 0 """ # code define functions supplied 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 exists. remove , 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') file in files:     text = mungefile(file)     outfile.write(text)  print '' print '   pmw.py has been created.'  if needcolor or needblt:     print '   before running freeze, copy following file(s):'     if needblt:         print '   ' + os.path.join(srcdir, 'pmwblt.py')     if needcolor:         print '   ' + os.path.join(srcdir, 'pmwcolor.py') 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -