1,前言
#!/usr/bin/python from pylab import * x = arange(-2,2,0.001) #x范围 y = 3*x*log(x)-1.0/36*exp(-(36.0*x-36.0/exp(1))**4) plt.plot(x,y) plt.title(u'LOL') #标签 plt.xlabel(u'x') plt.ylabel(u'y') plt.axis([-0.05,1.2,-1.5,0.2]) #坐标轴范围 text(0.0,0.05,r'$f(x)=3x{log}(x)-\frac{1}{36}e^{-(36x-\frac{36}{e})^4},fontsize=18) #公式显示 plt.grid(True) #网格显示 plt.show()4,打包成WIN程序
#Used successfully in Python2.5 with matplotlib 0.91.2 and PyQt4 (andQt 4.3.3) fromdistutils.core import setup importpy2exe #We need to import the glob module to search for all files. importglob #We need to exclude matplotlib backends not being used by thisexecutable. You may find #that you need different excludes to create a working executable withyour chosen backend. #We also need to include include various numerix libraries that theother functions call. opts= { 'py2exe':{ "includes" : [ "matplotlib.backends", "matplotlib.figure","pylab","numpy", "matplotlib.backends.backend_tkagg"], 'excludes':['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg', '_fltkagg','_gtk', '_gtkcairo', ], 'dll_excludes':['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll'] } } #Save matplotlib-data to mpl-data ( It is located in thematplotlib\mpl-data #folder and the compiled programs will look for it in \mpl-data #note: using matplotlib.get_mpldata_info data_files= [(r'mpl-data',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')), #Because matplotlibrc does not have an extension, glob does not findit (at least I think that's why) #So add it manually here: (r'mpl-data',[r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']), (r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\images\*.*')), (r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\*.*'))] #for console program use 'console = [{"script" :"scriptname.py"}] setup(windows=[{"script": "lol.py"}], options=opts, data_files=data_files)B,编译命令:
#setup.py fromdistutils.core import setup importpy2exe #setup(console=["lol.py"]) setup( options= { "py2exe":{ "dll_excludes":["MSVCP90.dll"],#开始没有这句 } }, windows=[{"script":"lol.py"}] )出现MSVCP90缺失问题,添加后正常,可以参照以下两篇文章:1,( 请猛击);2,( 请猛击);
***binary dependencies *** Yourexecutable(s) also depend on these dlls which are not included, youmay or may not need to distribute them. Makesure you have the license if you distribute any of them, and makesure you don't distribute files belonging to the operating system. OLEAUT32.dll- C:\Windows\system32\OLEAUT32.dll USER32.dll- C:\Windows\system32\USER32.dll IMM32.dll- C:\Windows\system32\IMM32.dll SHELL32.dll- C:\Windows\system32\SHELL32.dll ole32.dll- C:\Windows\system32\ole32.dll COMDLG32.dll- C:\Windows\system32\COMDLG32.dll fftpack_lite.pyd- C:\Python27\lib\site-packages\numpy\fft\fftpack_lite.pyd COMCTL32.dll- C:\Windows\system32\COMCTL32.dll ADVAPI32.dll- C:\Windows\system32\ADVAPI32.dll msvcrt.dll- C:\Windows\system32\msvcrt.dll WS2_32.dll- C:\Windows\system32\WS2_32.dll GDI32.dll- C:\Windows\system32\GDI32.dll KERNEL32.dll- C:\Windows\system32\KERNEL32.dll MSVCP90.dll– C:\Python27\MSVCP90.dll打包编译可能出现以上问题,把msvcp90.dll复制到dist文件夹里面,就可以了,这个文件在VC2008里面都有,不行网上搜一下。