473,738 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pyinstall and matplotlib

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,
Feb 9 '08 #1
4 9687
On Feb 9, 2:53 pm, John Henry <john106he...@h otmail.comwrote :
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).
Feb 13 '08 #2
In article
<31************ *************** *******@l16g200 0hsh.googlegrou ps.com>,
John Henry <jo**********@h otmail.comwrote :
On Feb 9, 2:53 pm, John Henry <john106he...@h otmail.comwrote :
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/WinShell>
import win32com
import py2exe.mf as modulefinder
for pth in win32com.__path __[1:]:
modulefinder.Ad dPackagePath("w in32com", pth)
for extra in ["win32com.shell "]:
__import__(extr a)
m = sys.modules[extra]
for pth in m.__path__[1:]:
modulefinder.Ad dPackagePath(ex tra, pth)

tuiRoot = os.path.dirname (os.path.dirnam e(os.path.abspa th(__file__)))
roRoot = os.path.join(tu iRoot, "ROPackage" )
sys.path = [tuiRoot, roRoot] + sys.path
import TUI.Version
mainProg = os.path.join(tu iRoot, "runtui.py" )

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

def addDataFiles(da taFiles, 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(f romDir)[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.startsw ith(fromDir):
raise RuntimeError("C annot deal with %r files; %s does not
start with %r" %\
(resBase, dirPath, fromDir))
toPath = os.path.join(to SubDir, dirPath[lenFromDir+1:])
filePaths = [os.path.join(di rPath, fileName) for fileName in
fileNames]
dataFiles.appen d((toPath, filePaths))

# Add resources
dataFiles = []
# TUI resources
for resBase in ("Help", "Scripts", "Sounds"):
toSubDir = os.path.join("T UI", resBase)
fromDir = os.path.join(tu iRoot, toSubDir)
addDataFiles(da taFiles, fromDir, toSubDir)
# RO resources
for resBase in ("Bitmaps",) :
toSubDir = os.path.join("R O", resBase)
fromDir = os.path.join(ro Root, toSubDir)
addDataFiles(da taFiles, fromDir, toSubDir)

# Add tcl snack libraries
pythonDir = os.path.dirname (sys.executable )
snackSubDir = "tcl\\snack 2.2"
snackDir = os.path.join(py thonDir, snackSubDir)
addDataFiles(da taFiles, snackDir, snackSubDir)

# Add matplotlib's data files.
matplotlibDataP ath = matplotlib.get_ data_path()
addDataFiles(da taFiles, matplotlibDataP ath, "matplotlibdata ")

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

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

inclModules = [
# "email.Util s", # needed for Python 2.5.0
]
# packages to include recursively
inclPackages = [
"TUI",
"RO",
"matplotlib ",
"dateutil", # required by matplotlib
"pytz", # required by matplotlib
# "matplotlib.bac kends",
# "matplotlib.num erix",
# "encodings" ,
# "numpy",
# "email", # needed for Python 2.5
]

setup(
options = dict(
py2exe = dict (
dll_excludes = [
# the following are for matplotlib 0.87:
"libgdk_pix buf-2.0-0.dll",
"libgobject-2.0-0.dll",
"libgdk-win32-2.0-0.dll",
"wxmsw26uh_vc.d ll",
],
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)
Feb 13 '08 #3
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
Feb 17 '08 #4
>>Traceback (most recent call last):
>> File "multicolor.py" , line 11, in ?
File "pylab.pyc" , line 1, in ?
File "matplotlib\pyl ab.pyc", line 222, in ?
File "matplotlib\bac kends\__init__. pyc", line 24, in pylab_setup
File "matplotlib\bac kends\backend_t kagg.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.p yc 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
Feb 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1770
by: John Hunter | last post by:
matplotlib is a 2D plotting package for python with a matlab compatible syntax and output tested under linux and windows platforms. matplotlib-0.30 is available for download at http://matplotlib.sourceforge.net, and has many new features since the last major release. Multiple outputs matplotlib now supports postscript and GD output, as well as the
3
2623
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many plot types: line plots, bar charts, log plots, images, pseudocolor plots, legends, date plots, finance charts and more. What's new since matplotlib 0.50 This is the first wide release in 5 months and there has been a tremendous amount of...
2
11649
by: Grant Edwards | last post by:
I downloaded examples/contour_demo.py, and it doesn't run. I've searched both the user guide and the Wiki for "contour" and got zero hits. http://matplotlib.sourceforge.net/matplotlib.pylab.html#-contour appears to be a good reference if you already know how to use contour(), but I could glean zero clues from it on how to actually use contour(). For example, it doesn't explain what the actual formats/types of the parameters. It...
0
2597
by: spross | last post by:
hi all i have to use matplotlib on mac os x. on the official site of matplotlib, i found a link to precompiled python packages for mac os x: http://pythonmac.org/packages/py24-fat/index.html so first, i installed python 2.4. that works great! if i type 'python' in the terminal, it loads python 2.4. after that, i loaded and installed the matplotlib package from this
4
3350
by: Bill Jackson | last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc: text.usetex : True I tried clearing the cache files under ~/.matplotlib, but this did not help the problem. I'd post on the matplotlib mailing list, but I have a hard enough time browsing sourceforge's achives (frequent internal server errors). Here is some output:
3
4721
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution on other comps... i used py2exe... i wrote a setup.py whose contents are : from distutils.core import setup import py2exe import matplotlib setup(console=, options={ 'py2exe': { 'packages' : ,
5
2405
by: Hartmut Goebel | last post by:
Hi, has anybody used McMillan Installer, PyInstall or py2exe cross-platform? I have a Windows partition with Python installed there, so this would "only" required working on a different directory and for a different OS. Since I'm working on Linux, it's awful to boot Windows each time I want to build a new release. Any hint in this area?
0
4330
by: PamMish1982 | last post by:
Hi all, I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe for this purpose but every time I try to make this exe using a setup file I get these errors. Final.py is my python code. Traceback (most recent call last): File "Final.py", line 5, in <module> File "pylab.pyc", line 1, in <module> File...
1
4062
by: Chriskim | last post by:
Hi I am having a very difficult time makine executable file using Py2exe. This program uses "matplotlib" to generate graphs and I think this is causing the errors What extra codes are necessary to make this work?? Here is what error said... Traceback (most recent call last): File "real_test.py", line 7, in <module> File "zipextimporter.pyc", line 82, in load_module File "matplotlib\__init__.pyc", line 709, in <module>
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.