I have been trying to make a single executable file and I am getting close. Please do not recommend that I use PyInstaller -- I have tried that route, asked on SO here, and have put in tickets. It is close but not quite working. I am now trying py2exe and am also very close. In pyinstaller, I am able to create resource files (which builds the executable with the files included -- I can then access these in the temporary folder).
I want to do the same for py2exe. I have a single executable, but five extra folders (maps, mpl-data, data, pics and tcl). I have seen this question but can't seem to understand it, nor get it to work. In my main py file, I am using PersistentDict(filepath)
which is where I need the path to the file.
My question is two parts: 1. How do I get the files (data files below) packaged into the executable. 2. How do I access these files in my code and return their path (as a string) such as /temp/file1.jpg.
Here is my code for my py2exe setup file -- note that I have matplotlib and must include the mpl-data correctly in my executable. Thanks!
from distutils.core import setup
import py2exe
import shutil
import glob
import matplotlib,six
opts = {'py2exe': { "includes" : ["matplotlib.backends",
"matplotlib.backends.backend_qt4agg",
"matplotlib.figure","numpy",
"six",
"mpl_toolkits.basemap",
"matplotlib.backends.backend_tkagg"],
'excludes': ['_gtkagg', '_tkagg','_agg2','_cairo',
'_cocoaagg', '_fltkagg', '_gtk', '_gtkcairo', 'tcl' ],
'dll_excludes': ['libgdk-win32-2.0-0.dll','w9xpopen.exe',
'libgobject-2.0-0.dll'],
'bundle_files': 1,
'dist_dir': "Dist Folder",
'compressed': True,
}
}
data_files = [(r'mpl-data', glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')),
(r'mpl-data', [r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\images\*.*')),
(r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\*.*')),
(r'mpl-data\data', glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\data\*.*')),
('data', ['C:\\Users\\Me\\Documents\\Example_Json_File.json']),
('pics', ['C:\\Users\\Me\\Documents\\Example_Icon.ico',
'C:\\Users\\Me\\Documents\\Example_Jpg.jpg',
])]
setup(windows=[{"script" : "MyMainScript.py",
"data_files" : data_files,
"icon_resources": [(1, 'C:\\Users\\Me\\Documents\\Example_Icon.ico')]}, ],
version = "1.0",
options=opts,
data_files=data_files,
zipfile = None,
)