From b26e31b0ab1be93f4a965ce60ae2cb55b237fcff Mon Sep 17 00:00:00 2001 From: Gordon Brockway Jr Date: Tue, 17 Nov 2015 12:39:02 -0500 Subject: [PATCH 1/4] This setup file for py2exe works at least somewhat. Now need to incorporate the climate data and other data. --- setup_py2exe.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 setup_py2exe.py diff --git a/setup_py2exe.py b/setup_py2exe.py new file mode 100644 index 0000000..ed6ee53 --- /dev/null +++ b/setup_py2exe.py @@ -0,0 +1,66 @@ +from distutils.core import setup +import py2exe + +# Remove the build folder, a bit slower but ensures that build contains the latest +import shutil +shutil.rmtree("build", ignore_errors=True) + +# my setup.py is based on one generated with gui2exe, so data_files is done a bit differently +data_files = [] +includes = [] +excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', + 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', + 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3' + ] +packages = ['pytz'] +dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', + 'tk84.dll'] +icon_resources = [] +bitmap_resources = [] +other_resources = [] + +# add the mpl mpl-data folder and rc file +import matplotlib as mpl +data_files += mpl.get_py2exe_datafiles() +data_files += "./Cold Climate Air-Source Heat Pump Listing.txt" +#data_files += "Climate Data/KBED-2002.txt" +# data_files += "Climate Data/KBED-2003.txt" +# data_files += "Climate Data/KBED-2004.txt" +# data_files += "Climate Data/KBED-2005.txt" +# data_files += "Climate Data/KBED-2006.txt" +# data_files += "Climate Data/KBED-2007.txt" +# data_files += "Climate Data/KBED-2008.txt" +# data_files += "Climate Data/KBED-2009.txt" +# data_files += "Climate Data/KBED-2010.txt" +# data_files += "Climate Data/KBED-2011.txt" +# data_files += "Climate Data/KBED-2012.txt" +# data_files += "Climate Data/KBED-2013.txt" +# data_files += "Climate Data/KBED-2014.txt" +# data_files += "Climate Data/KBED-2015.txt" +# data_files += "Residential Profiles/Default oil deliveries.txt" + +setup( + windows=[{"script" : "Heat Pump Analysis.py"}], + # compressed and optimize reduce the size + options = {"py2exe": {"compressed": 2, + "optimize": 2, + "includes": includes, + "excludes": excludes, + "packages": packages, + "dll_excludes": dll_excludes, + # using 2 to reduce number of files in dist folder + # using 1 is not recommended as it often does not work + "bundle_files": 2, + "dist_dir": 'dist', + "xref": False, + "skip_archive": False, + "ascii": False, + "custom_boot_script": '', + } + }, + + # using zipfile to reduce number of files in dist + zipfile = r'lib\library.zip', + + data_files=data_files +) \ No newline at end of file From dcc28a286db9f518ecc6cfee45eed8693a10d422 Mon Sep 17 00:00:00 2001 From: Gordon Brockway Jr Date: Wed, 18 Nov 2015 21:29:07 -0500 Subject: [PATCH 2/4] Further corrections to script for making an executable. This version creates subfolders in the dist folder for climate data, etc. It creates an exe, but the exe fails to run. Currently, the error has to do with the quit command. --- setup_py2exe.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/setup_py2exe.py b/setup_py2exe.py index ed6ee53..5f35d16 100644 --- a/setup_py2exe.py +++ b/setup_py2exe.py @@ -1,12 +1,16 @@ +import sys + +import glob + from distutils.core import setup import py2exe +import os # Remove the build folder, a bit slower but ensures that build contains the latest import shutil shutil.rmtree("build", ignore_errors=True) -# my setup.py is based on one generated with gui2exe, so data_files is done a bit differently -data_files = [] +matplot_lib_data_files = [] includes = [] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', @@ -21,23 +25,15 @@ # add the mpl mpl-data folder and rc file import matplotlib as mpl -data_files += mpl.get_py2exe_datafiles() -data_files += "./Cold Climate Air-Source Heat Pump Listing.txt" -#data_files += "Climate Data/KBED-2002.txt" -# data_files += "Climate Data/KBED-2003.txt" -# data_files += "Climate Data/KBED-2004.txt" -# data_files += "Climate Data/KBED-2005.txt" -# data_files += "Climate Data/KBED-2006.txt" -# data_files += "Climate Data/KBED-2007.txt" -# data_files += "Climate Data/KBED-2008.txt" -# data_files += "Climate Data/KBED-2009.txt" -# data_files += "Climate Data/KBED-2010.txt" -# data_files += "Climate Data/KBED-2011.txt" -# data_files += "Climate Data/KBED-2012.txt" -# data_files += "Climate Data/KBED-2013.txt" -# data_files += "Climate Data/KBED-2014.txt" -# data_files += "Climate Data/KBED-2015.txt" -# data_files += "Residential Profiles/Default oil deliveries.txt" +matplot_lib_data_files += mpl.get_py2exe_datafiles() + + +f2 = ("", [r'./Cold Climate Air-Source Heat Pump Listing.txt']) +matplot_lib_data_files.append(f2) + +matplot_lib_data_files.append(("Climate Data", glob.glob(r'.\Climate Data\*.*'))) + +matplot_lib_data_files.append(("Residential Profiles", glob.glob(r'.\Residential Profiles\Default oil deliveries.txt'))) setup( windows=[{"script" : "Heat Pump Analysis.py"}], @@ -62,5 +58,5 @@ # using zipfile to reduce number of files in dist zipfile = r'lib\library.zip', - data_files=data_files + data_files=matplot_lib_data_files ) \ No newline at end of file From ec2328c2b3f76b57c87aedb1ad1c847f8fc93740 Mon Sep 17 00:00:00 2001 From: Gordon Brockway Jr Date: Wed, 18 Nov 2015 21:38:48 -0500 Subject: [PATCH 3/4] import sys --- Heat Pump Analysis.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Heat Pump Analysis.py b/Heat Pump Analysis.py index ebf7f3f..15edaba 100644 --- a/Heat Pump Analysis.py +++ b/Heat Pump Analysis.py @@ -34,6 +34,8 @@ # heat pump cooling # matplotlib figure plotting library +import sys + import matplotlib matplotlib.use("TkAgg") from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2TkAgg From 9e1b5d8a31fdbb231864e1d983d389a72de2d515 Mon Sep 17 00:00:00 2001 From: Gordon Brockway Jr Date: Thu, 3 Dec 2015 10:22:31 -0500 Subject: [PATCH 4/4] fix installer --- Heat Pump Analysis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Heat Pump Analysis.py b/Heat Pump Analysis.py index 15edaba..8c63bfe 100644 --- a/Heat Pump Analysis.py +++ b/Heat Pump Analysis.py @@ -265,6 +265,9 @@ a4.set_autoscaley_on(True) plt.grid(True) +def quit(): + exit(0) + def popupmsg(title, msg): popup = tk.Tk()