将 py2exe 与 wxPython 和 Matplotlib 结合使用
我正在尝试从使用 wxPython 和 Matplotlib 的 python 脚本生成 .exe 文件,但这看起来是不可能的。
我正在执行的导入(与 Matplotlib 相关)如下:
from numpy import *
导入 matplotlib
matplotlib.interactive(True)
matplotlib.use("WXAgg")
从 matplotlib.figure 导入图
从 matplotlib.backends.backend_wxagg 导入FigureCanvasWxAgg 作为 FigCanvas
from matplotlib.ticker import MultipleLocator
这是我尝试使用的 setup.py 文件:
from distutils.core import setup
import py2exe
import matplotlib
opts = {
'py2exe': {"bundle_files" : 3,
"includes" : [ "matplotlib",
"matplotlib.backends",
"matplotlib.backends.backend_wxagg",
"numpy",
"matplotlib.ticker",
"matplotlib.figure", "_wxagg"],
'excludes': ['_gtkagg', '_tkagg', '_agg2',
'_cairo', '_cocoaagg',
'_fltkagg', '_gtk', '_gtkcairo', ],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll']
}
}
setup(
windows=[{'script':'starHunter.py', 'icon_resources':[(1, 'icon.ico')]}],
data_files=matplotlib.get_py2exe_datafiles(),
options=opts,
zipfile=None
)
尝试运行 .exe 文件后,我总是收到“找不到 matplotlib 数据文件”,顺便说一句,创建成功。
附加信息:我在 Windows XP 上使用 Python 2.6、Matplotlib 0.99.3、wxPython 2.8.11.0
提前致谢。 任何帮助将不胜感激!
干杯, 安德烈莎·西沃莱拉
I'm trying to generate an .exe file from a python script that uses wxPython and Matplotlib and it looks like to be impossible.
The imports I'm doing (related with Matplotlib) are the following:
from numpy import *
import matplotlib
matplotlib.interactive(True)
matplotlib.use("WXAgg")
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.ticker import MultipleLocator
Here is the setup.py file I'm trying to use:
from distutils.core import setup
import py2exe
import matplotlib
opts = {
'py2exe': {"bundle_files" : 3,
"includes" : [ "matplotlib",
"matplotlib.backends",
"matplotlib.backends.backend_wxagg",
"numpy",
"matplotlib.ticker",
"matplotlib.figure", "_wxagg"],
'excludes': ['_gtkagg', '_tkagg', '_agg2',
'_cairo', '_cocoaagg',
'_fltkagg', '_gtk', '_gtkcairo', ],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll']
}
}
setup(
windows=[{'script':'starHunter.py', 'icon_resources':[(1, 'icon.ico')]}],
data_files=matplotlib.get_py2exe_datafiles(),
options=opts,
zipfile=None
)
I'm always getting "Could not find matplotlib data files" after trying to run the .exe file, which by the way, is successfully created.
Additional information: I'm using Python 2.6, Matplotlib 0.99.3, wxPython 2.8.11.0 on Windows XP
Thanks in advance.
Any help will be appreciated!
Cheers,
Andressa Sivolella
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用 PyInstaller 而不是 py2exe。它完全支持 wxPython 和 matplotlib。与 py2exe 不同,它正在积极开发中。
Try using PyInstaller rather than py2exe. It has full support for wxPython and matplotlib. And it's in active development, unlike py2exe.
matplotlib.get_py2exe_datafiles() 有很多问题,如果它有效的话会很方便。指定要使用的后端也是一个好主意。这是我最近使用的工作 matplotlib 导入:
There are a number of problems with matplotlib.get_py2exe_datafiles(), as convenient as it would be if it worked. It's also a good idea to specify which backend to use. Here's a working matplotlib import I recently used:
为了进行简单的测试,您可以简单地将“site-packages\matplotlib”中的“mpl-data”文件夹复制到您的应用程序文件夹中。据我所知,“mpl-data”无法捆绑到单个可执行文件中,因此必须将其作为文件夹包含在您的二进制发行版中。
我通过 GUI2Exe 使用 py2exe,并且可以冻结使用 matplotlib + numpy/scipy + wx 的应用程序(显然是 wxagg 后端)。我不需要包含 _tkagg (它在对我有用的 GUI2Exe 默认设置中被明确排除)。
For a simply test, you could simply copy 'mpl-data' folder in 'site-packages\matplotlib' to your app folder. As far as I know, 'mpl-data' cannot be bundled into the single executable so this has to be included in your binary distribution as a folder.
I used py2exe via GUI2Exe and could freeze my app that uses matplotlib + numpy/scipy + wx (so obviously wxagg backend). I didn't need to include _tkagg (which is explicitly excluded in GUI2Exe default setting which worked for me).
Py2exe文档解释了问题的根源并给出了解决方案。这对我有用。 (matplotlib 版本 1.1.0,Python 2.7)
http://www.py2exe.org/index.cgi /MatPlotLib
由于我没有评论或评估其他答案的特权,因此我必须编写自己的答案。柯克的回答对我来说是最有价值的帮助。 PyInstaller 可能是一种解决方法(尚未测试),但绝对不是问题的技术解决方案!
Py2exe documentation explains the source of the problem and give solutions. It worked for me. (matplotlib version 1.1.0, Python 2.7)
http://www.py2exe.org/index.cgi/MatPlotLib
Since I have no privilege to comment or evaluate other answers, I have to write my own one. Kirk's answer was the most valuable help for me. PyInstaller might be a workaround (have not tested it) but is definitely not the technical solution to the problem !