[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

pyinstall and matplotlib

John Henry

2/9/2008 10:53:00 PM

Has anybody been able to create an exe of their python applications
involving matplotlib using pyinstall (ver 1.3)? I am getting a:

RuntimeError: Could not find the matplotlib data files

when I attempt to run the exe created.

In searching the web, it appears this is an issue when others tried to
use py2exe as well. Unfortunately, the few hits I saw doesn't include
enough details to inspire me as to what I should be doing in my
pyinstall .spec file.

Does anybody has an example or information about this?

Thanks,
9 Answers

John Henry

2/13/2008 11:41:00 AM

0

On Feb 9, 2:53 pm, John Henry <john106he...@hotmail.com> wrote:
> Has anybody been able to create an exe of their python applications
> involving matplotlib using pyinstall (ver 1.3)? I am getting a:
>
> RuntimeError: Could not find the matplotlib data files
>
> when I attempt to run the exe created.
>
> In searching the web, it appears this is an issue when others tried to
> use py2exe as well. Unfortunately, the few hits I saw doesn't include
> enough details to inspire me as to what I should be doing in my
> pyinstall .spec file.
>
> Does anybody has an example or information about this?
>
> Thanks,

Well, looks like nobody has an answer to this question.

How'bout py2exe or other ways of creating exe files out of matplotlib
projects? Has anybody been able to do that? (I am cross-posting
these messages to the matploblib mailing list).

Russell E. Owen

2/13/2008 6:07:00 PM

0

In article
<3144e444-3542-4550-a280-ff15da8bed0b@l16g2000hsh.googlegroups.com>,
John Henry <john106henry@hotmail.com> wrote:

> On Feb 9, 2:53 pm, John Henry <john106he...@hotmail.com> wrote:
> > Has anybody been able to create an exe of their python applications
> > involving matplotlib using pyinstall (ver 1.3)? I am getting a:
> >
> > RuntimeError: Could not find the matplotlib data files
> >
> > when I attempt to run the exe created.
> >
> > In searching the web, it appears this is an issue when others tried to
> > use py2exe as well. Unfortunately, the few hits I saw doesn't include
> > enough details to inspire me as to what I should be doing in my
> > pyinstall .spec file.
> >
> > Does anybody has an example or information about this?
> >
> > Thanks,
>
> Well, looks like nobody has an answer to this question.
>
> How'bout py2exe or other ways of creating exe files out of matplotlib
> projects? Has anybody been able to do that? (I am cross-posting
> these messages to the matploblib mailing list).

For py2exe I have appended a setup script I use to bundle an application
that includes matplotlib. I am no Windows expert and there are probably
better ways to do it, but it does work. I have made no attempt to strip
out extra stuff.

(As for pyinstaller:a year or so ago I tried to use it to make a bundled
*unix* version of my app. If that had worked I'd have considered trying
to use it for Windows as well. But after a lot of experimenting I was
never able to get anything even close to functional. Maybe it's better
now.)

-- Russell

from distutils.core import setup
import os
import sys
import matplotlib
import py2exe

# The following code is necessary for py2exe to find win32com.shell.
# Solution from
<http://starship.python.net/crew/theller/moin.cgi/Wi...
import win32com
import py2exe.mf as modulefinder
for pth in win32com.__path__[1:]:
modulefinder.AddPackagePath("win32com", pth)
for extra in ["win32com.shell"]:
__import__(extra)
m = sys.modules[extra]
for pth in m.__path__[1:]:
modulefinder.AddPackagePath(extra, pth)

tuiRoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
roRoot = os.path.join(tuiRoot, "ROPackage")
sys.path = [tuiRoot, roRoot] + sys.path
import TUI.Version
mainProg = os.path.join(tuiRoot, "runtui.py")

NDataFilesToPrint = 0 # number of data files to print, per directory

def addDataFiles(dataFiles, fromDir, toSubDir=None,
inclHiddenDirs=False):
"""Find data files and format data for the data_files argument of
setup.

In/Out:
- dataFiles: a list to which is appended zero or more of these
elements:
[subDir, list of paths to resource files]

Inputs:
- fromDir: path to root directory of existing resource files
- toSubDir: relative path to resources in package;
if omitted then the final dir of fromDir is used
- inclHiddenDirs: if True, the contents of directories whose names
start with "." are included

Returns a list of the following elements:
"""
lenFromDir = len(fromDir)
if toSubDir == None:
toSubDir = os.path.split(fromDir)[1]
for (dirPath, dirNames, fileNames) in os.walk(fromDir):
if not inclHiddenDirs:
numNames = len(dirNames)
for ii in range(numNames-1, -1, -1):
if dirNames[ii].startswith("."):
del(dirNames[ii])
if not dirPath.startswith(fromDir):
raise RuntimeError("Cannot deal with %r files; %s does not
start with %r" % (resBase, dirPath, fromDir))
toPath = os.path.join(toSubDir, dirPath[lenFromDir+1:])
filePaths = [os.path.join(dirPath, fileName) for fileName in
fileNames]
dataFiles.append((toPath, filePaths))

# Add resources
dataFiles = []
# TUI resources
for resBase in ("Help", "Scripts", "Sounds"):
toSubDir = os.path.join("TUI", resBase)
fromDir = os.path.join(tuiRoot, toSubDir)
addDataFiles(dataFiles, fromDir, toSubDir)
# RO resources
for resBase in ("Bitmaps",):
toSubDir = os.path.join("RO", resBase)
fromDir = os.path.join(roRoot, toSubDir)
addDataFiles(dataFiles, fromDir, toSubDir)

# Add tcl snack libraries
pythonDir = os.path.dirname(sys.executable)
snackSubDir = "tcl\\snack2.2"
snackDir = os.path.join(pythonDir, snackSubDir)
addDataFiles(dataFiles, snackDir, snackSubDir)

# Add matplotlib's data files.
matplotlibDataPath = matplotlib.get_data_path()
addDataFiles(dataFiles, matplotlibDataPath, "matplotlibdata")

if NDataFilesToPrint > 0:
print "\nData files:"
for pathInfo in dataFiles:
print pathInfo[0]
nFiles = len(pathInfo[1])
for resPath in pathInfo[1][0:NDataFilesToPrint]:
print " ", resPath
if nFiles > NDataFilesToPrint:
print " ...and %d more" % (nFiles - NDataFilesToPrint)

versDate = TUI.Version.VersionStr
appVers = versDate.split()[0]
distDir = "TUI_%s_Windows" % (appVers,)

inclModules = [
# "email.Utils", # needed for Python 2.5.0
]
# packages to include recursively
inclPackages = [
"TUI",
"RO",
"matplotlib",
"dateutil", # required by matplotlib
"pytz", # required by matplotlib
# "matplotlib.backends",
# "matplotlib.numerix",
# "encodings",
# "numpy",
# "email", # needed for Python 2.5
]

setup(
options = dict(
py2exe = dict (
dll_excludes = [
# the following are for matplotlib 0.87:
"libgdk_pixbuf-2.0-0.dll",
"libgobject-2.0-0.dll",
"libgdk-win32-2.0-0.dll",
"wxmsw26uh_vc.dll",
],
excludes = [ # modules to exclude
"_gtkagg",
"_wxagg",
],
#includes = inclModules,
packages = inclPackages,
)
),
windows=[ # windows= for no console, console= for console
dict(
script = mainProg,
dest_base = "TUI",
icon_resources = [(1, "TUI.ico")],
),
],
data_files = dataFiles,
)

# rename dist to final directory name
os.rename("dist", distDir)

John Henry

2/14/2008 7:17:00 PM

0

Thank you for the response. I am having trouble using the script. I
am assuming the TUI is the application this script was developed for
and did my best to replace that with the name of my own.

To make things simple, let's say we take one of the sample matplotlib
program MULTICOLOR.PY and place that in a directory by itself. I have
attached the modified script below. Notice that I commented out the
"import TUI.Version" and replaced TUI.Version.VersionStr with some
arbitrary number. I have to create a directroy "dest" before running
it.

When I run this script, there is no error message. Just:

running install
running build
running install_data

and then there is an empty directory "MULTICOLOR_2.31_Windows" created
and then nothing else.

#=================================
from distutils.core import setup
import os
import sys
import matplotlib
import py2exe

# The following code is necessary for py2exe to find win32com.shell.
# Solution from <http://starship.python.net/crew/theller...
WinShell>

import win32com
import py2exe.mf as modulefinder

for pth in win32com.__path__[1:]:
modulefinder.AddPackagePath("win32com", pth)
for extra in ["win32com.shell"]:
__import__(extra)
m = sys.modules[extra]
for pth in m.__path__[1:]:
modulefinder.AddPackagePath(extra, pth)

tuiRoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
roRoot = os.path.join(tuiRoot, "ROPackage")
sys.path = [tuiRoot, roRoot] + sys.path

#import TUI.Version

mainProg = os.path.join(tuiRoot, "multicolor.py")

NDataFilesToPrint = 0 # number of data files to print, per directory

def addDataFiles(dataFiles, fromDir, toSubDir=None,
inclHiddenDirs=False):
"""
Find data files and format data for the data_files argument of
setup.

In/Out:
- dataFiles: a list to which is appended zero or more of these
elements:
[subDir, list of paths to resource files]

Inputs:
- fromDir: path to root directory of existing resource files
- toSubDir: relative path to resources in package;
if omitted then the final dir of fromDir is used
- inclHiddenDirs: if True, the contents of directories whose
names
start with "." are included

Returns a list of the following elements:
"""
lenFromDir = len(fromDir)
if toSubDir == None:
toSubDir = os.path.split(fromDir)[1]
for (dirPath, dirNames, fileNames) in os.walk(fromDir):
if not inclHiddenDirs:
numNames = len(dirNames)
for ii in range(numNames-1, -1, -1):
if dirNames[ii].startswith("."):
del(dirNames[ii])
if not dirPath.startswith(fromDir):
raise RuntimeError("Cannot deal with %r files; %s does not
start with %r" % (resBase, dirPath, fromDir))
toPath = os.path.join(toSubDir, dirPath[lenFromDir+1:])
filePaths = [os.path.join(dirPath, fileName) for fileName in
fileNames]
dataFiles.append((toPath, filePaths))

# Add resources
dataFiles = []
# TUI resources
for resBase in ("Help", "Scripts", "Sounds"):
toSubDir = os.path.join("MULTICOLOR", resBase)
fromDir = os.path.join(tuiRoot, toSubDir)
addDataFiles(dataFiles, fromDir, toSubDir)
# RO resources
for resBase in ("Bitmaps",):
toSubDir = os.path.join("RO", resBase)
fromDir = os.path.join(roRoot, toSubDir)
addDataFiles(dataFiles, fromDir, toSubDir)

# Add tcl snack libraries
pythonDir = os.path.dirname(sys.executable)
snackSubDir = "tcl\\snack2.2"
snackDir = os.path.join(pythonDir, snackSubDir)
addDataFiles(dataFiles, snackDir, snackSubDir)

# Add matplotlib's data files.
matplotlibDataPath = matplotlib.get_data_path()
addDataFiles(dataFiles, matplotlibDataPath, "matplotlibdata")

if NDataFilesToPrint > 0:
print "\nData files:"
for pathInfo in dataFiles:
print pathInfo[0]
nFiles = len(pathInfo[1])
for resPath in pathInfo[1][0:NDataFilesToPrint]:
print " ", resPath
if nFiles > NDataFilesToPrint:
print " ...and %d more" % (nFiles - NDataFilesToPrint)

versDate = "2.31" # TUI.Version.VersionStr
appVers = versDate.split()[0]
distDir = "MULTICOLOR_%s_Windows" % (appVers,)

inclModules = [
# "email.Utils", # needed for Python 2.5.0
]
# packages to include recursively
inclPackages = [
"MULTICOLOR",
"RO",
"matplotlib",
"dateutil", # required by matplotlib
"pytz", # required by matplotlib
# "matplotlib.backends",
# "matplotlib.numerix",
# "encodings",
# "numpy",
# "email", # needed for Python 2.5
]

setup(
options = dict(
py2exe = dict (
dll_excludes = [
# the following are for matplotlib 0.87:
"libgdk_pixbuf-2.0-0.dll",
"libgobject-2.0-0.dll",
"libgdk-win32-2.0-0.dll",
"wxmsw26uh_vc.dll",
],
excludes = [ # modules to exclude
"_gtkagg",
"_wxagg",
],
#includes = inclModules,
packages = inclPackages,
)
),
windows=[ # windows= for no console, console= for console
dict(
script = mainProg,
dest_base = "MULTICOLOR",
icon_resources = [(1, "python.ico")],
),
],
data_files = dataFiles,
)

# rename dist to final directory name
os.rename("dist", distDir)



On Feb 13, 10:07 am, "Russell E. Owen" <ro...@cesmail.net> wrote:
> In article
> <3144e444-3542-4550-a280-ff15da8be...@l16g2000hsh.googlegroups.com>,
> John Henry <john106he...@hotmail.com> wrote:
>
>
>
> > On Feb 9, 2:53 pm, John Henry <john106he...@hotmail.com> wrote:
> > > Has anybody been able to create an exe of their python applications
> > > involving matplotlib using pyinstall (ver 1.3)? I am getting a:
>
> > > RuntimeError: Could not find the matplotlib data files
>
> > > when I attempt to run the exe created.
>
> > > In searching the web, it appears this is an issue when others tried to
> > > use py2exe as well. Unfortunately, the few hits I saw doesn't include
> > > enough details to inspire me as to what I should be doing in my
> > > pyinstall .spec file.
>
> > > Does anybody has an example or information about this?
>
> > > Thanks,
>
> > Well, looks like nobody has an answer to this question.
>
> > How'bout py2exe or other ways of creating exe files out of matplotlib
> > projects? Has anybody been able to do that? (I am cross-posting
> > these messages to the matploblib mailing list).
>
> For py2exe I have appended a setup script I use to bundle an application
> that includes matplotlib. I am no Windows expert and there are probably
> better ways to do it, but it does work. I have made no attempt to strip
> out extra stuff.
>
> (As for pyinstaller:a year or so ago I tried to use it to make a bundled
> *unix* version of my app. If that had worked I'd have considered trying
> to use it for Windows as well. But after a lot of experimenting I was
> never able to get anything even close to functional. Maybe it's better
> now.)
>
> -- Russell
>
> from distutils.core import setup
> import os
> import sys
> import matplotlib
> import py2exe
>
> # The following code is necessary for py2exe to find win32com.shell.
> # Solution from
> <http://starship.python.net/crew/theller...WinShell>
> import win32com
> import py2exe.mf as modulefinder
> for pth in win32com.__path__[1:]:
> modulefinder.AddPackagePath("win32com", pth)
> for extra in ["win32com.shell"]:
> __import__(extra)
> m = sys.modules[extra]
> for pth in m.__path__[1:]:
> modulefinder.AddPackagePath(extra, pth)
>
> tuiRoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> roRoot = os.path.join(tuiRoot, "ROPackage")
> sys.path = [tuiRoot, roRoot] + sys.path
> import TUI.Version
> mainProg = os.path.join(tuiRoot, "runtui.py")
>
> NDataFilesToPrint = 0 # number of data files to print, per directory
>
> def addDataFiles(dataFiles, fromDir, toSubDir=None,
> inclHiddenDirs=False):
> """Find data files and format data for the data_files argument of
> setup.
>
> In/Out:
> - dataFiles: a list to which is appended zero or more of these
> elements:
> [subDir, list of paths to resource files]
>
> Inputs:
> - fromDir: path to root directory of existing resource files
> - toSubDir: relative path to resources in package;
> if omitted then the final dir of fromDir is used
> - inclHiddenDirs: if True, the contents of directories whose names
> start with "." are included
>
> Returns a list of the following elements:
> """
> lenFromDir = len(fromDir)
> if toSubDir == None:
> toSubDir = os.path.split(fromDir)[1]
> for (dirPath, dirNames, fileNames) in os.walk(fromDir):
> if not inclHiddenDirs:
> numNames = len(dirNames)
> for ii in range(numNames-1, -1, -1):
> if dirNames[ii].startswith("."):
> del(dirNames[ii])
> if not dirPath.startswith(fromDir):
> raise RuntimeError("Cannot deal with %r files; %s does not
> start with %r" %> (resBase, dirPath, fromDir))
> toPath = os.path.join(toSubDir, dirPath[lenFromDir+1:])
> filePaths = [os.path.join(dirPath, fileName) for fileName in
> fileNames]
> dataFiles.append((toPath, filePaths))
>
> # Add resources
> dataFiles = []
> # TUI resources
> for resBase in ("Help", "Scripts", "Sounds"):
> toSubDir = os.path.join("TUI", resBase)
> fromDir = os.path.join(tuiRoot, toSubDir)
> addDataFiles(dataFiles, fromDir, toSubDir)
> # RO resources
> for resBase in ("Bitmaps",):
> toSubDir = os.path.join("RO", resBase)
> fromDir = os.path.join(roRoot, toSubDir)
> addDataFiles(dataFiles, fromDir, toSubDir)
>
> # Add tcl snack libraries
> pythonDir = os.path.dirname(sys.executable)
> snackSubDir = "tcl\\snack2.2"
> snackDir = os.path.join(pythonDir, snackSubDir)
> addDataFiles(dataFiles, snackDir, snackSubDir)
>
> # Add matplotlib's data files.
> matplotlibDataPath = matplotlib.get_data_path()
> addDataFiles(dataFiles, matplotlibDataPath, "matplotlibdata")
>
> if NDataFilesToPrint > 0:
> print "\nData files:"
> for pathInfo in dataFiles:
> print pathInfo[0]
> nFiles = len(pathInfo[1])
> for resPath in pathInfo[1][0:NDataFilesToPrint]:
> print " ", resPath
> if nFiles > NDataFilesToPrint:
> print " ...and %d more" % (nFiles - NDataFilesToPrint)
>
> versDate = TUI.Version.VersionStr
> appVers = versDate.split()[0]
> distDir = "TUI_%s_Windows" % (appVers,)
>
> inclModules = [
> # "email.Utils", # needed for Python 2.5.0
> ]
> # packages to include recursively
> inclPackages = [
> "TUI",
> "RO",
> "matplotlib",
> "dateutil", # required by matplotlib
> "pytz", # required by matplotlib
> # "matplotlib.backends",
> # "matplotlib.numerix",
> # "encodings",
> # "numpy",
> # "email", # needed for Python 2.5
> ]
>
> setup(
> options = dict(
> py2exe = dict (
> dll_excludes = [
> # the following are for matplotlib 0.87:
> "libgdk_pixbuf-2.0-0.dll",
> "libgobject-2.0-0.dll",
> "libgdk-win32-2.0-0.dll",
> "wxmsw26uh_vc.dll",
> ],
> excludes = [ # modules to exclude
> "_gtkagg",
> "_wxagg",
> ],
> #includes = inclModules,
> packages = inclPackages,
> )
> ),
> windows=[ # windows= for no console, console= for console
> dict(
> script = mainProg,
> dest_base = "TUI",
> icon_resources = [(1, "TUI.ico")],
> ),
> ],
> data_files = dataFiles,
> )
>
> # rename dist to final directory name
> os.rename("dist", distDir)

John Henry

2/17/2008 5:40:00 PM

0

Anybody willing to help?

On Feb 14, 11:17 am, John Henry <john106he...@hotmail.com> wrote:
> Thank you for the response. I am having trouble using the script. I
> am assuming the TUI is the application this script was developed for
> and did my best to replace that with the name of my own.
>
> To make things simple, let's say we take one of the sample matplotlib
> program MULTICOLOR.PY and place that in a directory by itself. I have
> attached the modified script below. Notice that I commented out the
> "import TUI.Version" and replaced TUI.Version.VersionStr with some
> arbitrary number. I have to create a directroy "dest" before running
> it.
>
> When I run this script, there is no error message. Just:
>
> running install
> running build
> running install_data
>
> and then there is an empty directory "MULTICOLOR_2.31_Windows" created
> and then nothing else.
>
> #=================================
> from distutils.core import setup
> import os
> import sys
> import matplotlib
> import py2exe
>
> # The following code is necessary for py2exe to find win32com.shell.
> # Solution from <http://starship.python.net/crew/theller...
> WinShell>
>
> import win32com
> import py2exe.mf as modulefinder
>
> for pth in win32com.__path__[1:]:
> modulefinder.AddPackagePath("win32com", pth)
> for extra in ["win32com.shell"]:
> __import__(extra)
> m = sys.modules[extra]
> for pth in m.__path__[1:]:
> modulefinder.AddPackagePath(extra, pth)
>
> tuiRoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> roRoot = os.path.join(tuiRoot, "ROPackage")
> sys.path = [tuiRoot, roRoot] + sys.path
>
> #import TUI.Version
>
> mainProg = os.path.join(tuiRoot, "multicolor.py")
>
> NDataFilesToPrint = 0 # number of data files to print, per directory
>
> def addDataFiles(dataFiles, fromDir, toSubDir=None,
> inclHiddenDirs=False):
> """
> Find data files and format data for the data_files argument of
> setup.
>
> In/Out:
> - dataFiles: a list to which is appended zero or more of these
> elements:
> [subDir, list of paths to resource files]
>
> Inputs:
> - fromDir: path to root directory of existing resource files
> - toSubDir: relative path to resources in package;
> if omitted then the final dir of fromDir is used
> - inclHiddenDirs: if True, the contents of directories whose
> names
> start with "." are included
>
> Returns a list of the following elements:
> """
> lenFromDir = len(fromDir)
> if toSubDir == None:
> toSubDir = os.path.split(fromDir)[1]
> for (dirPath, dirNames, fileNames) in os.walk(fromDir):
> if not inclHiddenDirs:
> numNames = len(dirNames)
> for ii in range(numNames-1, -1, -1):
> if dirNames[ii].startswith("."):
> del(dirNames[ii])
> if not dirPath.startswith(fromDir):
> raise RuntimeError("Cannot deal with %r files; %s does not
> start with %r" %> (resBase, dirPath, fromDir))
> toPath = os.path.join(toSubDir, dirPath[lenFromDir+1:])
> filePaths = [os.path.join(dirPath, fileName) for fileName in
> fileNames]
> dataFiles.append((toPath, filePaths))
>
> # Add resources
> dataFiles = []
> # TUI resources
> for resBase in ("Help", "Scripts", "Sounds"):
> toSubDir = os.path.join("MULTICOLOR", resBase)
> fromDir = os.path.join(tuiRoot, toSubDir)
> addDataFiles(dataFiles, fromDir, toSubDir)
> # RO resources
> for resBase in ("Bitmaps",):
> toSubDir = os.path.join("RO", resBase)
> fromDir = os.path.join(roRoot, toSubDir)
> addDataFiles(dataFiles, fromDir, toSubDir)
>
> # Add tcl snack libraries
> pythonDir = os.path.dirname(sys.executable)
> snackSubDir = "tcl\\snack2.2"
> snackDir = os.path.join(pythonDir, snackSubDir)
> addDataFiles(dataFiles, snackDir, snackSubDir)
>
> # Add matplotlib's data files.
> matplotlibDataPath = matplotlib.get_data_path()
> addDataFiles(dataFiles, matplotlibDataPath, "matplotlibdata")
>
> if NDataFilesToPrint > 0:
> print "\nData files:"
> for pathInfo in dataFiles:
> print pathInfo[0]
> nFiles = len(pathInfo[1])
> for resPath in pathInfo[1][0:NDataFilesToPrint]:
> print " ", resPath
> if nFiles > NDataFilesToPrint:
> print " ...and %d more" % (nFiles - NDataFilesToPrint)
>
> versDate = "2.31" # TUI.Version.VersionStr
> appVers = versDate.split()[0]
> distDir = "MULTICOLOR_%s_Windows" % (appVers,)
>
> inclModules = [
> # "email.Utils", # needed for Python 2.5.0
> ]
> # packages to include recursively
> inclPackages = [
> "MULTICOLOR",
> "RO",
> "matplotlib",
> "dateutil", # required by matplotlib
> "pytz", # required by matplotlib
> # "matplotlib.backends",
> # "matplotlib.numerix",
> # "encodings",
> # "numpy",
> # "email", # needed for Python 2.5
> ]
>
> setup(
> options = dict(
> py2exe = dict (
> dll_excludes = [
> # the following are for matplotlib 0.87:
> "libgdk_pixbuf-2.0-0.dll",
> "libgobject-2.0-0.dll",
> "libgdk-win32-2.0-0.dll",
> "wxmsw26uh_vc.dll",
> ],
> excludes = [ # modules to exclude
> "_gtkagg",
> "_wxagg",
> ],
> #includes = inclModules,
> packages = inclPackages,
> )
> ),
> windows=[ # windows= for no console, console= for console
> dict(
> script = mainProg,
> dest_base = "MULTICOLOR",
> icon_resources = [(1, "python.ico")],
> ),
> ],
> data_files = dataFiles,
> )
>
> # rename dist to final directory name
> os.rename("dist", distDir)
>
> On Feb 13, 10:07 am, "Russell E. Owen" <ro...@cesmail.net> wrote:
>
> > In article
> > <3144e444-3542-4550-a280-ff15da8be...@l16g2000hsh.googlegroups.com>,
> > John Henry <john106he...@hotmail.com> wrote:
>
> > > On Feb 9, 2:53 pm, John Henry <john106he...@hotmail.com> wrote:
> > > > Has anybody been able to create an exe of their python applications
> > > > involving matplotlib using pyinstall (ver 1.3)? I am getting a:
>
> > > > RuntimeError: Could not find the matplotlib data files
>
> > > > when I attempt to run the exe created.
>
> > > > In searching the web, it appears this is an issue when others tried to
> > > > use py2exe as well. Unfortunately, the few hits I saw doesn't include
> > > > enough details to inspire me as to what I should be doing in my
> > > > pyinstall .spec file.
>
> > > > Does anybody has an example or information about this?
>
> > > > Thanks,
>
> > > Well, looks like nobody has an answer to this question.
>
> > > How'bout py2exe or other ways of creating exe files out of matplotlib
> > > projects? Has anybody been able to do that? (I am cross-posting
> > > these messages to the matploblib mailing list).
>
> > For py2exe I have appended a setup script I use to bundle an application
> > that includes matplotlib. I am no Windows expert and there are probably
> > better ways to do it, but it does work. I have made no attempt to strip
> > out extra stuff.
>
> > (As for pyinstaller:a year or so ago I tried to use it to make a bundled
> > *unix* version of my app. If that had worked I'd have considered trying
> > to use it for Windows as well. But after a lot of experimenting I was
> > never able to get anything even close to functional. Maybe it's better
> > now.)
>
> > -- Russell
>
> > from distutils.core import setup
> > import os
> > import sys
> > import matplotlib
> > import py2exe
>
> > # The following code is necessary for py2exe to find win32com.shell.
> > # Solution from
> > <http://starship.python.net/crew/theller...WinShell>
> > import win32com
> > import py2exe.mf as modulefinder
> > for pth in win32com.__path__[1:]:
> > modulefinder.AddPackagePath("win32com", pth)
> > for extra in ["win32com.shell"]:
> > __import__(extra)
> > m = sys.modules[extra]
> > for pth in m.__path__[1:]:
> > modulefinder.AddPackagePath(extra, pth)
>
> > tuiRoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> > roRoot = os.path.join(tuiRoot, "ROPackage")
> > sys.path = [tuiRoot, roRoot] + sys.path
> > import TUI.Version
> > mainProg = os.path.join(tuiRoot, "runtui.py")
>
> > NDataFilesToPrint = 0 # number of data files to print, per directory
>
> > def addDataFiles(dataFiles, fromDir, toSubDir=None,
> > inclHiddenDirs=False):
> > """Find data files and format data for the data_files argument of
> > setup.
>
> > In/Out:
> > - dataFiles: a list to which is appended zero or more of these
> > elements:
> > [subDir, list of paths to resource files]
>
> > Inputs:
> > - fromDir: path to root directory of existing resource files
> > - toSubDir: relative path to resources in package;
> > if omitted then the final dir of fromDir is used
> > - inclHiddenDirs: if True, the contents of directories whose names
> > start with "." are included
>
> > Returns a list of the following elements:
> > """
> > lenFromDir = len(fromDir)
> > if toSubDir == None:
> > toSubDir = os.path.split(fromDir)[1]
> > for (dirPath, dirNames, fileNames) in os.walk(fromDir):
> > if not inclHiddenDirs:
> > numNames = len(dirNames)
> > for ii in range(numNames-1, -1, -1):
> > if dirNames[ii].startswith("."):
> > del(dirNames[ii])
> > if not dirPath.startswith(fromDir):
> > raise RuntimeError("Cannot deal with %r files; %s does not
> > start with %r" %> > (resBase, dirPath, fromDir))
> > toPath = os.path.join(toSubDir, dirPath[lenFromDir+1:])
> > filePaths = [os.path.join(dirPath, fileName) for fileName in
> > fileNames]
> > dataFiles.append((toPath, filePaths))
>
> > # Add resources
> > dataFiles = []
> > # TUI resources
> > for resBase in ("Help", "Scripts", "Sounds"):
> > toSubDir = os.path.join("TUI", resBase)
> > fromDir = os.path.join(tuiRoot, toSubDir)
> > addDataFiles(dataFiles, fromDir, toSubDir)
> > # RO resources
> > for resBase in ("Bitmaps",):
> > toSubDir = os.path.join("RO", resBase)
> > fromDir = os.path.join(roRoot, toSubDir)
> > addDataFiles(dataFiles, fromDir, toSubDir)
>
> > # Add tcl snack libraries
> > pythonDir = os.path.dirname(sys.executable)
> > snackSubDir = "tcl\\snack2.2"
> > snackDir = os.path.join(pythonDir,
>
> ...
>
> read more »

Stef Mientki

2/17/2008 7:51:00 PM

0

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_Wanted = True

from distutils.core import setup
import py2exe
import sys
subdirs = [ '..\\P24_support', '..\\P24_pictures',
'..\\P24_Lib_Extensions' ]
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_Python\\P24_PyLab_Works\\build',
'D:\\Data_Python\\P24_PyLab_Works\\dist' ]
for path in dist_paths :
if File_Exists ( path ) :
shutil.rmtree ( path )
# ***********************************************************************



# ***********************************************************************
# ***********************************************************************
data_files = []
packages = []
includes = []
excludes = []
dll_excludes = []
data_files.append ( ( '', glob.glob ( 'templates_*.*' ) ) )



# ***********************************************************************
# For MatPlotLib
# ***********************************************************************
if MatPlotLib_Wanted :
import matplotlib

includes.append ( 'matplotlib.numerix.random_array' )

packages.append ( 'matplotlib' )
packages.append ( 'pytz' )

data_files.append ( ( r'mpl-data', glob.glob (
r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\*.*' )))
data_files.append ( ( r'mpl-data', glob.glob (

r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc' )))
data_files.append ( ( r'mpl-data\\images', glob.glob (
r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\images\\*.*' )))
data_files.append ( ( r'mpl-data\\fonts\\afm', glob.glob (

r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\afm\\*.*' )))
data_files.append ( ( r'mpl-data\\fonts\\pdfcorefonts', glob.glob (

r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\pdfcorefonts\\*.*'
)))
data_files.append ( ( r'mpl-data\\fonts\\ttf', glob.glob (

r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\*.*' )))

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_cocoaagg' )
excludes.append ( 'Tkconstants' )
excludes.append ( 'Tkinter' )
excludes.append ( 'tcl' )
excludes.append ( "_imagingtk" )
excludes.append ( "PIL._imagingtk" )
excludes.append ( "ImageTk" )
excludes.append ( "PIL.ImageTk" )
excludes.append ( "FixTk" )

dll_excludes.append ( 'libgdk-win32-2.0-0.dll' )
dll_excludes.append ( 'libgdk_pixbuf-2.0-0.dll' )
dll_excludes.append ( 'libgobject-2.0-0.dll')
dll_excludes.append ( 'tcl84.dll' )
dll_excludes.append ( 'tk84.dll' )
dll_excludes.append ( 'tclpip84.dll' )
# ***********************************************************************


# seems not to be found (imported in brick.py)
includes.append ( 'PyLab_Works_properties' )

# ***********************************************************************
# ***********************************************************************



# 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_Works\PyLab_Works.iss'])

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.backends.backend_wxagg import Toolbar, FigureManager
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib import rcParams, mlab, cm
from matplotlib.mlab import meshgrid
from matplotlib.figure import Figure
from matplotlib.axes import Subplot


hope this might help you somewhat,
cheers,
Stef

John Henry

2/19/2008 3:35:00 AM

0

On Feb 17, 11:50 am, Stef Mientki <stef.mien...@gmail.com> wrote:
> 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_Wanted = True
>
> from distutils.core import setup
> import py2exe
> import sys
> subdirs = [ '..\\P24_support', '..\\P24_pictures',
> '..\\P24_Lib_Extensions' ]
> 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_Python\\P24_PyLab_Works\\build',
> 'D:\\Data_Python\\P24_PyLab_Works\\dist' ]
> for path in dist_paths :
> if File_Exists ( path ) :
> shutil.rmtree ( path )
> # ***********************************************************************
>
> # ***********************************************************************
> # ***********************************************************************
> data_files = []
> packages = []
> includes = []
> excludes = []
> dll_excludes = []
> data_files.append ( ( '', glob.glob ( 'templates_*.*' ) ) )
>
> # ***********************************************************************
> # For MatPlotLib
> # ***********************************************************************
> if MatPlotLib_Wanted :
> import matplotlib
>
> includes.append ( 'matplotlib.numerix.random_array' )
>
> packages.append ( 'matplotlib' )
> packages.append ( 'pytz' )
>
> data_files.append ( ( r'mpl-data', glob.glob (
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\*.*' )))
> data_files.append ( ( r'mpl-data', glob.glob (
>
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc' )))
> data_files.append ( ( r'mpl-data\\images', glob.glob (
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\images\\*.*' )))
> data_files.append ( ( r'mpl-data\\fonts\\afm', glob.glob (
>
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\afm\\*.*' )))
> data_files.append ( ( r'mpl-data\\fonts\\pdfcorefonts', glob.glob (
>
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\pdfcorefonts\\*.*'
> )))
> data_files.append ( ( r'mpl-data\\fonts\\ttf', glob.glob (
>
> r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\*.*' )))
>
> 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_cocoaagg' )
> excludes.append ( 'Tkconstants' )
> excludes.append ( 'Tkinter' )
> excludes.append ( 'tcl' )
> excludes.append ( "_imagingtk" )
> excludes.append ( "PIL._imagingtk" )
> excludes.append ( "ImageTk" )
> excludes.append ( "PIL.ImageTk" )
> excludes.append ( "FixTk" )
>
> dll_excludes.append ( 'libgdk-win32-2.0-0.dll' )
> dll_excludes.append ( 'libgdk_pixbuf-2.0-0.dll' )
> dll_excludes.append ( 'libgobject-2.0-0.dll')
> dll_excludes.append ( 'tcl84.dll' )
> dll_excludes.append ( 'tk84.dll' )
> dll_excludes.append ( 'tclpip84.dll' )
> # ***********************************************************************
>
> # seems not to be found (imported in brick.py)
> includes.append ( 'PyLab_Works_properties' )
>
> # ***********************************************************************
> # ***********************************************************************
>
> # 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_Works\PyLab_Works.iss'])
>
> 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.backends.backend_wxagg > import Toolbar, FigureManager
> from matplotlib.backends.backend_wxagg > import FigureCanvasWxAgg as FigureCanvas
> from matplotlib import rcParams, mlab, cm
> from matplotlib.mlab import meshgrid
> from matplotlib.figure import Figure
> from matplotlib.axes import Subplot
>
> hope this might help you somewhat,
> cheers,
> Stef

Steve,

Thanks for your help.

Using your code as a starter, I've gone a lot further. I have now
gone pass the point where matplotlib was unable to find its
datafiles. However, the program now stops because it can't get
Tkinter started. The error message in the log says:

Traceback (most recent call last):
File "multicolor.py", line 11, in ?
File "pylab.pyc", line 1, in ?
File "matplotlib\pylab.pyc", line 222, in ?
File "matplotlib\backends\__init__.pyc", line 24, in pylab_setup
File "matplotlib\backends\backend_tkagg.pyc", line 7, in ?
ImportError: No module named Tkinter

Any ideas?

Thanks,

John Henry

2/19/2008 4:04:00 AM

0

On Feb 18, 7:34 pm, John Henry <john106he...@hotmail.com> wrote:
> On Feb 17, 11:50 am, Stef Mientki <stef.mien...@gmail.com> wrote:
>
>
>
> > 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_Wanted = True
>
> > from distutils.core import setup
> > import py2exe
> > import sys
> > subdirs = [ '..\\P24_support', '..\\P24_pictures',
> > '..\\P24_Lib_Extensions' ]
> > 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_Python\\P24_PyLab_Works\\build',
> > 'D:\\Data_Python\\P24_PyLab_Works\\dist' ]
> > for path in dist_paths :
> > if File_Exists ( path ) :
> > shutil.rmtree ( path )
> > # ***********************************************************************
>
> > # ***********************************************************************
> > # ***********************************************************************
> > data_files = []
> > packages = []
> > includes = []
> > excludes = []
> > dll_excludes = []
> > data_files.append ( ( '', glob.glob ( 'templates_*.*' ) ) )
>
> > # ***********************************************************************
> > # For MatPlotLib
> > # ***********************************************************************
> > if MatPlotLib_Wanted :
> > import matplotlib
>
> > includes.append ( 'matplotlib.numerix.random_array' )
>
> > packages.append ( 'matplotlib' )
> > packages.append ( 'pytz' )
>
> > data_files.append ( ( r'mpl-data', glob.glob (
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\*.*' )))
> > data_files.append ( ( r'mpl-data', glob.glob (
>
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc' )))
> > data_files.append ( ( r'mpl-data\\images', glob.glob (
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\images\\*.*' )))
> > data_files.append ( ( r'mpl-data\\fonts\\afm', glob.glob (
>
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\afm\\*.*' )))
> > data_files.append ( ( r'mpl-data\\fonts\\pdfcorefonts', glob.glob (
>
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\pdfcorefonts\\*.*'
> > )))
> > data_files.append ( ( r'mpl-data\\fonts\\ttf', glob.glob (
>
> > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\*.*' )))
>
> > 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_cocoaagg' )
> > excludes.append ( 'Tkconstants' )
> > excludes.append ( 'Tkinter' )
> > excludes.append ( 'tcl' )
> > excludes.append ( "_imagingtk" )
> > excludes.append ( "PIL._imagingtk" )
> > excludes.append ( "ImageTk" )
> > excludes.append ( "PIL.ImageTk" )
> > excludes.append ( "FixTk" )
>
> > dll_excludes.append ( 'libgdk-win32-2.0-0.dll' )
> > dll_excludes.append ( 'libgdk_pixbuf-2.0-0.dll' )
> > dll_excludes.append ( 'libgobject-2.0-0.dll')
> > dll_excludes.append ( 'tcl84.dll' )
> > dll_excludes.append ( 'tk84.dll' )
> > dll_excludes.append ( 'tclpip84.dll' )
> > # ***********************************************************************
>
> > # seems not to be found (imported in brick.py)
> > includes.append ( 'PyLab_Works_properties' )
>
> > # ***********************************************************************
> > # ***********************************************************************
>
> > # 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_Works\PyLab_Works.iss'])
>
> > 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.backends.backend_wxagg > > import Toolbar, FigureManager
> > from matplotlib.backends.backend_wxagg > > import FigureCanvasWxAgg as FigureCanvas
> > from matplotlib import rcParams, mlab, cm
> > from matplotlib.mlab import meshgrid
> > from matplotlib.figure import Figure
> > from matplotlib.axes import Subplot
>
> > hope this might help you somewhat,
> > cheers,
> > Stef
>
> Steve,
>
> Thanks for your help.
>
> Using your code as a starter, I've gone a lot further. I have now
> gone pass the point where matplotlib was unable to find its
> datafiles. However, the program now stops because it can't get
> Tkinter started. The error message in the log says:
>
> Traceback (most recent call last):
> File "multicolor.py", line 11, in ?
> File "pylab.pyc", line 1, in ?
> File "matplotlib\pylab.pyc", line 222, in ?
> File "matplotlib\backends\__init__.pyc", line 24, in pylab_setup
> File "matplotlib\backends\backend_tkagg.pyc", line 7, in ?
> ImportError: No module named Tkinter
>
> Any ideas?
>
> Thanks,

BTW: I don't use Tkinter for GUI, I use PythonCard and wxPython. May
be the Tkinter is invoked by the multicolor.py sample?

John Henry

2/19/2008 5:15:00 AM

0

On Feb 18, 8:04 pm, John Henry <john106he...@hotmail.com> wrote:
> On Feb 18, 7:34 pm, John Henry <john106he...@hotmail.com> wrote:
>
>
>
> > On Feb 17, 11:50 am, Stef Mientki <stef.mien...@gmail.com> wrote:
>
> > > 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_Wanted = True
>
> > > from distutils.core import setup
> > > import py2exe
> > > import sys
> > > subdirs = [ '..\\P24_support', '..\\P24_pictures',
> > > '..\\P24_Lib_Extensions' ]
> > > 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_Python\\P24_PyLab_Works\\build',
> > > 'D:\\Data_Python\\P24_PyLab_Works\\dist' ]
> > > for path in dist_paths :
> > > if File_Exists ( path ) :
> > > shutil.rmtree ( path )
> > > # ***********************************************************************
>
> > > # ***********************************************************************
> > > # ***********************************************************************
> > > data_files = []
> > > packages = []
> > > includes = []
> > > excludes = []
> > > dll_excludes = []
> > > data_files.append ( ( '', glob.glob ( 'templates_*.*' ) ) )
>
> > > # ***********************************************************************
> > > # For MatPlotLib
> > > # ***********************************************************************
> > > if MatPlotLib_Wanted :
> > > import matplotlib
>
> > > includes.append ( 'matplotlib.numerix.random_array' )
>
> > > packages.append ( 'matplotlib' )
> > > packages.append ( 'pytz' )
>
> > > data_files.append ( ( r'mpl-data', glob.glob (
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\*.*' )))
> > > data_files.append ( ( r'mpl-data', glob.glob (
>
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc' )))
> > > data_files.append ( ( r'mpl-data\\images', glob.glob (
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\images\\*.*' )))
> > > data_files.append ( ( r'mpl-data\\fonts\\afm', glob.glob (
>
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\afm\\*.*' )))
> > > data_files.append ( ( r'mpl-data\\fonts\\pdfcorefonts', glob.glob (
>
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\pdfcorefonts\\*.*'
> > > )))
> > > data_files.append ( ( r'mpl-data\\fonts\\ttf', glob.glob (
>
> > > r'P:\\Python\\Lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\*.*' )))
>
> > > 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_cocoaagg' )
> > > excludes.append ( 'Tkconstants' )
> > > excludes.append ( 'Tkinter' )
> > > excludes.append ( 'tcl' )
> > > excludes.append ( "_imagingtk" )
> > > excludes.append ( "PIL._imagingtk" )
> > > excludes.append ( "ImageTk" )
> > > excludes.append ( "PIL.ImageTk" )
> > > excludes.append ( "FixTk" )
>
> > > dll_excludes.append ( 'libgdk-win32-2.0-0.dll' )
> > > dll_excludes.append ( 'libgdk_pixbuf-2.0-0.dll' )
> > > dll_excludes.append ( 'libgobject-2.0-0.dll')
> > > dll_excludes.append ( 'tcl84.dll' )
> > > dll_excludes.append ( 'tk84.dll' )
> > > dll_excludes.append ( 'tclpip84.dll' )
> > > # ***********************************************************************
>
> > > # seems not to be found (imported in brick.py)
> > > includes.append ( 'PyLab_Works_properties' )
>
> > > # ***********************************************************************
> > > # ***********************************************************************
>
> > > # 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_Works\PyLab_Works.iss'])
>
> > > 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.backends.backend_wxagg > > > import Toolbar, FigureManager
> > > from matplotlib.backends.backend_wxagg > > > import FigureCanvasWxAgg as FigureCanvas
> > > from matplotlib import rcParams, mlab, cm
> > > from matplotlib.mlab import meshgrid
> > > from matplotlib.figure import Figure
> > > from matplotlib.axes import Subplot
>
> > > hope this might help you somewhat,
> > > cheers,
> > > Stef
>
> > Steve,
>
> > Thanks for your help.
>
> > Using your code as a starter, I've gone a lot further. I have now
> > gone pass the point where matplotlib was unable to find its
> > datafiles. However, the program now stops because it can't get
> > Tkinter started. The error message in the log says:
>
> > Traceback (most recent call last):
> > File "multicolor.py", line 11, in ?
> > File "pylab.pyc", line 1, in ?
> > File "matplotlib\pylab.pyc", line 222, in ?
> > File "matplotlib\backends\__init__.pyc", line 24, in pylab_setup
> > File "matplotlib\backends\backend_tkagg.pyc", line 7, in ?
> > ImportError: No module named Tkinter
>
> > Any ideas?
>
> > Thanks,
>
> BTW: I don't use Tkinter for GUI, I use PythonCard and wxPython. May
> be the Tkinter is invoked by the multicolor.py sample?

I tried another application which I know for sure doesn't use Tkinter
and yet it still tries to invoke Tkinter. So, I need to disable the
backend_tkagg.pyc somehow.

Any suggestions?

Thanks,

Stef Mientki

2/19/2008 9:58:00 AM

0

>>> Traceback (most recent call last):
>>> File "multicolor.py", line 11, in ?
>>> File "pylab.pyc", line 1, in ?
>>> File "matplotlib\pylab.pyc", line 222, in ?
>>> File "matplotlib\backends\__init__.pyc", line 24, in pylab_setup
>>> File "matplotlib\backends\backend_tkagg.pyc", line 7, in ?
>>> ImportError: No module named Tkinter
>>> Any ideas?
>>> Thanks,
>> BTW: I don't use Tkinter for GUI, I use PythonCard and wxPython. May
>> be the Tkinter is invoked by the multicolor.py sample?
>
> I tried another application which I know for sure doesn't use Tkinter
> and yet it still tries to invoke Tkinter. So, I need to disable the
> backend_tkagg.pyc somehow.
>
> Any suggestions?
>
> Thanks,

hi John,

I've started a discussion on the MatPlotLib list,
(and others, but now limited to matplotlib-list)
you might want to follow the discussion over there.
I just read that the real solution seems to be in setup.cfg,
and AFAIK that file is missing in the distro.

cheers,
Stef