By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

regarding making an exe (of a package using matplotlib) using py2exe

P: 15
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 :
Expand|Select|Wrap|Line Numbers
  1. from distutils.core import setup
  2. import py2exe
  3. import matplotlib
  4.  
  5. setup(console=['letsc.py'],
  6. options={
  7. 'py2exe': {
  8. 'packages' : ['matplotlib', 'pytz'],
  9. }
  10. },
  11. data_files=[matplotlib.get_py2exe_datafiles()])
  12.  
as per the site http://www.py2exe.org/index.cgi/MatPlotLib... welll in the command prompt (not >>>) i typed [in the correct directory] "python setup.py py2exe". it gave out a lot of text on the console but finally in the end it displayed "error: can't copy 'F:\Python25\Lib\site-packages\matplotlib\mpl-data\fonts' : does'nt exist or not a regular file" (when actually there is a directory called mpl-data which has 3 subdirectories ... afm, pdfcorefonts and ttf) and the process stops.
It creates the usual dist and build folders but there isnt the required exe in the dist folder...
so i tried this setup.py:
Expand|Select|Wrap|Line Numbers
  1. # setup.py
  2. from distutils.core import setup
  3. import glob
  4. import py2exe
  5. import matplotlib
  6.  
  7. data = glob.glob(r'F:\Python25\Lib\site-packages\matplotlib\*\*\*\*\*')
  8.  
  9. setup(windows=["letsc.py"],
  10.      options={
  11.              'py2exe': {
  12.                         'packages' : ['matplotlib', 'pytz'],
  13.                        }
  14.             },
  15.  
  16.             data_files=[("matplotlibdata",data)],
  17.       )
Well... here it successfully compiles and i get a letsc.exe but on running it the error log says:
Exception in Tkinter callback
Traceback (most recent call last):
File "Tkinter.pyc", line 1403, in __call__
File "letsc.py", line 49, in Display
File "matplotlib\pylab.pyc", line 2023, in plot
File "matplotlib\pylab.pyc", line 937, in ishold
File "matplotlib\pylab.pyc", line 883, in gca
File "matplotlib\pylab.pyc", line 893, in gcf
File "matplotlib\pylab.pyc", line 859, in figure
File "matplotlib\backends\backend_tkagg.pyc", line 90, in new_figure_manager
File "matplotlib\backends\backend_tkagg.pyc", line 274, in __init__
File "matplotlib\backends\backend_tkagg.pyc", line 545, in __init__
File "matplotlib\backend_bases.pyc", line 1163, in __init__
File "matplotlib\backends\backend_tkagg.pyc", line 590, in _init_toolbar
File "matplotlib\backends\backend_tkagg.pyc", line 573, in _Button
File "Tkinter.pyc", line 3270, in __init__
File "Tkinter.pyc", line 3226, in __init__
TclError: couldn't open "F:\Python25\dist\matplotlibdata\images\home.p pm": no such file or directory
... basically now matplotlib seems 2 b a pain in the ***... sorry for the long post... but any help?
Jun 15 '07 #1
Share this Question
Share on Google+
3 Replies


bartonc
Expert 5K+
P: 6,596
I know that this is not exactly what you are looking for, but there is a script here that will do all the command-line stuff when it is run (in the proper directory) and shows how to start using "includes" and "excludes".

Hope that helps.
Jun 15 '07 #2

P: 15
I know that this is not exactly what you are looking for,
Bartonc appreciate ur help a lot... thanx... but thr's not a word of matplotlib in thr... basically the whole pain is tht matplotlib's modules or watever they r called arnt being put in the dist folder... see i'll put in my .py script also... mebbe tht mite help... here it is ........ letsc.py:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3.  
  4. class GUIFramework(Frame):
  5.     """This is the GUI"""
  6.  
  7.     def __init__(self,master=None):
  8.         """Initialize yourself"""
  9.  
  10.         """Initialise the base class"""
  11.         Frame.__init__(self,master)
  12.  
  13.         """Set the Window Title"""
  14.         self.master.title("Type Some Text")
  15.  
  16.         """Display the main window"
  17.         with a little bit of padding"""
  18.         self.grid(padx=10,pady=10)
  19.         self.CreateWidgets()
  20.  
  21.     def CreateWidgets(self):
  22.         """Create all the widgets that we need"""
  23.  
  24.         """Create the Text"""
  25.  
  26.  
  27.         """Create the Entry, set it to be a bit wider"""
  28.         self.enText1 = Entry(self)
  29.         self.enText1.grid(row=0, column=1, columnspan=3)
  30.  
  31.         self.enText2 = Entry(self)
  32.         self.enText2.grid(row=1, column=1, columnspan=3)
  33.  
  34.         self.enText3 = Entry(self)
  35.         self.enText3.grid(row=2, column=1, columnspan=3)
  36.  
  37.  
  38.         """Create the Button, set the text and the 
  39.         command that will be called when the button is clicked"""
  40.         self.btnDisplay = Button(self, text="Display!", command=self.Display)
  41.         self.btnDisplay.grid(row=0, column=4)
  42.  
  43.     def Display(self):
  44.         from pylab import *
  45.         """Called when btnDisplay is clicked, displays the contents of self.enText"""
  46.         t = arange(0.0, 2.0, 0.01)
  47.         s = (float(self.enText1.get()))*t*t + (float(self.enText2.get()))*t + (float(self.enText3.get()))
  48.         plot(t, s, linewidth=1.0)
  49.  
  50.         xlabel('x (m)')
  51.         ylabel('T (K)')
  52.         title('The sought after Graph!!!')
  53.         grid(True)
  54.         show()        
  55. if __name__ == "__main__":
  56.     guiFrame = GUIFramework()
  57.     guiFrame.mainloop()
  58.  
in short if i click the display button it shud pop out a graph [using the libraries of matplotlib] in my face but for some reason wen i click on display i get the error message in the log as seen in my previous post... any ideas guys? seriously py2exe+matplotlib==frustration as i read sumwhere while googling!!!
Jun 15 '07 #3

bartonc
Expert 5K+
P: 6,596
I know that this is not exactly what you are looking for, but there is a script here that will do all the command-line stuff when it is run (in the proper directory) and shows how to start using "includes" and "excludes".

Hope that helps.
Frustration is just a frame of mind. Trial and error are part of this process. My point was that you must learn (from the error messages) which modules are not automatically being included. Then using a script that will do all the command-line stuff for you (to reduce the frustration factor), you'll get to PLAY with the includes option until the errors abate.

And have fun. You'll be the expert in this area in no time!
Jun 16 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.