py2exe`ImportError:没有名为backend_tkagg`的模块

问题描述 投票:9回答:3

我试图从使用matplotlib的python脚本生成一个Windows可执行文件,似乎我得到一个常见的错误。

将文件“run.py”,第29行,在导入matplotlib.pyplot中作为plt文件“matplotlib \ pyplot.pyc”,第95行,在文件“matplotlib \ backends__init __。pyc”,第25行,在pylab_setup中导入错误:没有名为backend_tkagg的模块

问题是我在互联网上搜索时没有找到解决方案。

这是我的setup.py

from distutils.core import setup
import matplotlib
import py2exe 
matplotlib.use('TkAgg')
setup(data_files=matplotlib.get_py2exe_datafiles(),console=['run.py'])
python matplotlib py2exe
3个回答
5
投票

首先,简单的问题是,后端安装了吗?在我的Fedora系统上,我不得不从基础matplotlib单独安装它。

在Python控制台上你可以:

>>> import matplotlib.backends.backend_tkagg

如果可行,则强制py2exe包含它。在你的配置中:

opts = {
  'py2exe': { "includes" : ["matplotlib.backends.backend_tkagg"] }
}

2
投票

如果您使用的是py2exe,则它不会处理.egg格式的Python模块。如果您使用easy_install来安装故障模块,那么您可能只有.egg版本。有关如何修复它的更多信息,请参阅py2exe站点。

http://www.py2exe.org/index.cgi/ExeWithEggs


0
投票

这很好用

来自distutils.core导入设置导入py2exe,sys,os导入matplotlib

sys.setrecursionlimit(12000)sys.argv.append('py2exe')

setup(options = {“py2exe”:{“bundle_files”:3,“compressed”:True,“includes”:[“matplotlib.backends.backend_tkagg”]}},windows = [{“script”:“script.py “}],

zipfile = None,

data_files = matplotlib data_files = matplotlib.get_py2exe_datafiles(),)

© www.soinside.com 2019 - 2024. All rights reserved.