节食 py2exe 和 matplotlib
我目前正在开发一个应用程序,该应用程序使用 py2exe 从一些利用 matplotlib 的 Python 代码创建 exe 文件。它工作得很好,只是我的可执行文件很大。运行下面的转换脚本会创建 43.5 MB 的包(exe 及其依赖项)。我知道可能可以采取一些措施来缩小应用程序的大小。
有什么减少应用程序大小的建议吗?
我的转换脚本:
from distutils.core import setup
import py2exe
import matplotlib
setup(
windows=[{'script': r'ElectronOrbitalGenerator.py'}],
data_files=matplotlib.get_py2exe_datafiles(),
options={r'py2exe':{r'includes': r'ElementConfig',
r'includes': r'ColorConv',
r'includes': r'Tkinter',
r'includes': r're',
r'includes': r'math',
r'includes': r'sys',
r'includes': r'matplotlib',
r'includes': r'mpl_toolkits',
r'dll_excludes': [r'MSVCP90.dll'],
}},
)
这些是我的程序需要运行的所有模块:
import ElementConfig, ColorConv
import Tkinter, re, math, sys
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
I'm currently working on an application that uses py2exe to make an exe file from a bit of Python code that utilizes matplotlib. It's working pretty well except that my executables are massive. Running the conversion script below it creates 43.5 mb package (the exe and its dependencies). I know that there are probably some things that can be done to trim down the size of my application.
Any tips for cutting down the size of my application?
My conversion script:
from distutils.core import setup
import py2exe
import matplotlib
setup(
windows=[{'script': r'ElectronOrbitalGenerator.py'}],
data_files=matplotlib.get_py2exe_datafiles(),
options={r'py2exe':{r'includes': r'ElementConfig',
r'includes': r'ColorConv',
r'includes': r'Tkinter',
r'includes': r're',
r'includes': r'math',
r'includes': r'sys',
r'includes': r'matplotlib',
r'includes': r'mpl_toolkits',
r'dll_excludes': [r'MSVCP90.dll'],
}},
)
These are all the modules my program needs to run:
import ElementConfig, ColorConv
import Tkinter, re, math, sys
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 matplotlib 只是为了使用默认字体等显示一些图表,您只需删除
dist/mpl-data
文件夹中除 matplotlib.conf 和 matplotlibrc 之外的所有内容。我这样做了,在 12MB 上节省了大约 4MB。
为什么你的 dist 是 43.5MB 可能并不全是由于 matplotlib...
If you're using matplotlib just to show some chart using default font etc you can just delete in
dist/mpl-data
folder all but matplotlib.conf and matplotlibrc.I did this and saved up abot 4MB on 12MB.
Why your dist is 43.5MB probably is not all due to matplotlib...