matplotlib and py2exe

Hello Werner,
here is the file I try to compile.
It gave an error of missing DLL when i try to launch :frowning:
no Idea why, since with you example everything works
(I'm using maplotlib 0.87.7)

Giorgio

路路路

------------------------------------------------------------------------

import pylab as pyl
from scipy import *
from pyautosct import *
x=pyl.load('c:/temp/iris.txt')
#def pynipals
#return (lmat,smat,qcont,tcont,smat2,qcont2,tcont2)
[o,c]=x.shape
aut=raw_input('Autoscale data [y] or [n] ?')
# Start of autoscaling
if aut=='y':
vard=var(x,axis=0)*(o/(o-1.0))
stdn=sqrt(vard)# it differs from std in Matlab(tm) where std is normalised
stdon=ones((o,1))*stdn
xmeann=ones((o,1))*x.mean(axis=0)
xnorm=(x-xmeann)/stdon
x=xnorm
# End of autoscaling
smat=zeros((o,c))
lmat=zeros((c,c))
xt=x
if o>c:
vp=zeros((1,o))
varexp=zeros((1,o))
else:
vp=zeros((1,c))
varexp=zeros((1,c))
t=0
vartot=(x**2).sum()
sts=raw_input('Variance to be retained (max 99) ?')
st=int(sts)
st=round(st,1)
while vp.sum()<st:
t=t+1
ss=(x**2).sum(axis=0)
#ss=round_(ss, decimals=8)
a=sort(ss)
b=ss.argsort(kind='merge')
xmax=xt[:,b[c-1]]
s=(xmax*xmax).sum()
diffi=1000
while diffi>0.0000001:
聽聽rmax=dot(xmax,xt)/s
聽聽rmaxsq=(rmax*rmax).sum()
聽聽rmax=rmax/sqrt(rmaxsq)
聽聽xmax=dot(xt,rmax)
聽聽s2=(xmax*xmax).sum()
聽聽diffi=abs(s2-s)
聽聽s=s2 smat[:,t-1]=xmax
lmat[t-1,:]=rmax
varexp[0,t-1]=(xmax*xmax).sum()
vp[0,t-1]=varexp[0,t-1]/vartot*100
xmaxc=xmax[:,pyl.NewAxis]
xt=xt-xmaxc*rmax
print vp
print diffi
ncs=raw_input('How many components ?')
nc=int(ncs)
lmat=lmat[arange(0,nc),:]
smat=smat[:,arange(0,nc)]
[a,b]=smat.shape
##### Computation of T2 values
t2=zeros((o,1))
vvv=zeros((nc,nc))
for i in arange(1,nc+1):
vvv[i-1,i-1]=varexp[0,i-1]/(o-1)
for i in arange(1,o+1):
t2[i-1]= dot(dot(smat[i-1,arange(0,nc)],linalg.inv(vvv)),smat[i-1,arange(0,nc)])
### T2 contributions
ssq=empty((nc,1))
for i in arange(1,nc+1): ssq[i-1,0]=vvv[i-1,i-1]
h=(1./sqrt(ssq))
k=h[:,0]
#it has to be a vector before using diag
tcont=dot(dot(dot(x,lmat.transpose()),diag((k))),lmat)
#Comparison with matlab -= ok =-
# Computation of Q values based on cross-validation (ng deletion groups)
ng=5;
q=zeros((o,1))
qcont=zeros((o,c))
for g in arange(1,ng+1):
t=arange(g,o+1,ng)
smattr=zeros((o,c))
lmattr=zeros((c,c))
xtr=x;
xtr=delete(xtr,t-1, axis=0)
xev=x[t-1,:]
[rtr,c]=xtr.shape
if aut=='y':
聽聽sst=diag(ones((rtr,1))*std(xtr,axis=0)*sqrt((rtr/(rtr-1.0))))
聽聽jj1=min(sst)
聽聽jj2=argmin(sst)
聽聽if jj1==0:
聽聽聽print 'Error: variable ', int(jj2), ' constant in group ', int(g)
聽聽aa=pyautosct(xtr,xev)
聽聽xtr=aa[arange(0,rtr),:]
聽聽[aah,aak]=aa.shape
聽聽xev=aa[arange(rtr,size(aa,0)),:]
#Comparison with matlab -= ok =-
xttr=xtr
[ttrh,ttrk]=xttr.shape
tt=0
##checked
while tt<nc:
聽聽smattr=zeros((ttrh,nc))
聽聽lmattr=zeros((nc,c))
聽聽tt=tt+1
聽聽ss=(xttr**2).sum(axis=0)
聽聽a2=sort(ss)
聽聽b2=ss.argsort(kind='merge')
聽聽xmax=xttr[:,b2[c-1]]
聽聽s=(xmax*xmax).sum()
##checked
聽聽diffi=1000
聽聽while diffi>0.0000001:
聽聽聽rmax=dot(xmax,xttr)/s
聽聽聽rmaxsq=(rmax*rmax).sum()
聽聽聽rmax=rmax/sqrt(rmaxsq)
聽聽聽xmax=dot(xttr,rmax)
聽聽聽s2=(xmax*xmax).sum()
聽聽聽diffi=abs(s2-s)
聽聽聽s=s2
聽聽##checked
聽聽smattr[:,tt-1]=xmax
聽聽lmattr[tt-1,:]=rmax
聽聽xmaxc=xmax[:,pyl.NewAxis]
聽聽xttr=xttr-xmaxc*rmax
smatev=dot(xev,lmattr.transpose())
reconstrev=dot(smatev,lmattr)
for i in arange(1,size(xev,0)+1):
聽聽tind=t-1
聽聽q[tind[i-1]]=((reconstrev[i-1,:]-xev[i-1,:])*(reconstrev[i-1,:]-xev[i-1,:])).sum()
聽聽qcont[tind[i-1]]=(reconstrev[i-1,:]-xev[i-1,:])**2
print 'smat'
print smat
print 'lmat'
print lmat
print 'tcont'
print tcont
print 'qcont'
print qcont

Hi Giorgio,

Had a quick look at pylab based scripts and got an error on backend_tkagg when py2exe it. It looks like one needs to force the backend to be included, I used tkagg but you would have to replace that with wxagg for your script.

Attached is a setup.py and from the examples the file simple_plot.py.

Werner

setup.py (3.69 KB)

simple_plot.py (369 Bytes)