hi John,
John Henry wrote:
Anybody willing to help?
I struggled the past few days with the same problem,
and with the help of Werner Bruhin (wxPython list) I found a solution.
I had 2 problems:
- not finding mpl datapath
- matplotlib insisted on installing backends that were distorted on my
system
The first problem was solved with the following script:
it has some special parts
- remove the distro and build directories before running setup
- a special matplot part, ensuring mpl-data is copied and installed
- a lot of excludes for matplotlib ( which doesn't seem to work :-( )
Kill_Distro = True
MatPlotLib_Want ed = True
from distutils.core import setup
import py2exe
import sys
subdirs = [ '..\\P24_suppor t', '..\\P24_pictur es',
'..\\P24_Lib_Ex tensions' ]
for subdir in subdirs:
if not ( subdir in sys.path) : sys.path.append ( subdir )
from file_support import *
import shutil
import glob
# *************** *************** *************** *************** ***********
# Some suggests that old build/dist should be cleared
# *************** *************** *************** *************** ***********
dist_paths = [ 'D:\\Data_Pytho n\\P24_PyLab_Wo rks\\build',
'D:\\Data_Pytho n\\P24_PyLab_Wo rks\\dist' ]
for path in dist_paths :
if File_Exists ( path ) :
shutil.rmtree ( path )
# *************** *************** *************** *************** ***********
# *************** *************** *************** *************** ***********
# *************** *************** *************** *************** ***********
data_files = []
packages = []
includes = []
excludes = []
dll_excludes = []
data_files.appe nd ( ( '', glob.glob ( 'templates_*.*' ) ) )
# *************** *************** *************** *************** ***********
# For MatPlotLib
# *************** *************** *************** *************** ***********
if MatPlotLib_Want ed :
import matplotlib
includes.append ( 'matplotlib.num erix.random_arr ay' )
packages.append ( 'matplotlib' )
packages.append ( 'pytz' )
data_files.appe nd ( ( r'mpl-data', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\*.*' )))
data_files.appe nd ( ( r'mpl-data', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\matplotli brc' )))
data_files.appe nd ( ( r'mpl-data\\images', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\images\\* .*' )))
data_files.appe nd ( ( r'mpl-data\\fonts\\af m', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\fonts\\af m\\*.*' )))
data_files.appe nd ( ( r'mpl-data\\fonts\\pd fcorefonts', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\fonts\\pd fcorefonts\\*.* '
)))
data_files.appe nd ( ( r'mpl-data\\fonts\\tt f', glob.glob (
r'P:\\Python\\L ib\\site-packages\\matpl otlib\\mpl-data\\fonts\\tt f\\*.*' )))
excludes.append ( '_gtkagg')
excludes.append ( '_tkagg' )
excludes.append ( '_agg2' )
excludes.append ( '_cairo' )
excludes.append ( '_cocoaagg' )
excludes.append ( '_fltkagg' )
excludes.append ( '_gtk' )
excludes.append ( '_gtkcairo')
excludes.append ( 'backend_qt' )
excludes.append ( 'backend_qt4')
excludes.append ( 'backend_qt4agg ' )
excludes.append ( 'backend_qtagg' )
excludes.append ( 'backend_cairo' )
excludes.append ( 'backend_cocoaa gg' )
excludes.append ( 'Tkconstants' )
excludes.append ( 'Tkinter' )
excludes.append ( 'tcl' )
excludes.append ( "_imagingtk " )
excludes.append ( "PIL._imagingtk " )
excludes.append ( "ImageTk" )
excludes.append ( "PIL.ImageT k" )
excludes.append ( "FixTk" )
dll_excludes.ap pend ( 'libgdk-win32-2.0-0.dll' )
dll_excludes.ap pend ( 'libgdk_pixbuf-2.0-0.dll' )
dll_excludes.ap pend ( 'libgobject-2.0-0.dll')
dll_excludes.ap pend ( 'tcl84.dll' )
dll_excludes.ap pend ( 'tk84.dll' )
dll_excludes.ap pend ( 'tclpip84.dll' )
# *************** *************** *************** *************** ***********
# seems not to be found (imported in brick.py)
includes.append ( 'PyLab_Works_pr operties' )
# *************** *************** *************** *************** ***********
# *************** *************** *************** *************** ***********
# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
sys.argv.append ("py2exe")
setup (
windows = ['PyLab_Works.py '] ,
options = {
'py2exe' : {
'includes' : includes,
'excludes' : excludes,
'dll_excludes' : dll_excludes,
'packages' : packages,
}},
data_files = data_files
)
import subprocess
result = subprocess.call (
[ 'P:\Program Files\Inno Setup 4\ISCC.exe',
'D:\Data_Python \P24_PyLab_Work s\PyLab_Works.i ss'])
if (result==0) and Kill_Distro :
for path in dist_paths :
if File_Exists ( path ) :
shutil.rmtree ( path )
Thé essential issue is not to use pylab to do the imports for you,
but perform your own imports,
this might be a lot of work: in my case the import looks like this
(I don't include numerix, because I use numpy),
so in my program to distribute, I use this :
import matplotlib
matplotlib.use( 'WXAgg')
from matplotlib.back ends.backend_wx agg \
import Toolbar, FigureManager
from matplotlib.back ends.backend_wx agg \
import FigureCanvasWxA gg as FigureCanvas
from matplotlib import rcParams, mlab, cm
from matplotlib.mlab import meshgrid
from matplotlib.figu re import Figure
from matplotlib.axes import Subplot
hope this might help you somewhat,
cheers,
Stef