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

时间:2021-03-09 11:33:59

I am trying to make a windows executable from a python script that uses matplotlib and it seems that I am getting a common error.

我正在尝试从使用matplotlib的python脚本中创建一个windows可执行文件,似乎我得到了一个常见的错误。

File "run.py", line 29, in import matplotlib.pyplot as plt File "matplotlib\pyplot.pyc", line 95, in File "matplotlib\backends__init__.pyc", line 25, in pylab_setup ImportError: No module named backend_tkagg

文件”。第29行,导入matplotlib。作为plt文件的pyplot“matplotlib\pyplot”。第95行,在文件“matplotlib\backends__init__”中。pylab_setup ImportError:没有名为backend_tkagg的模块

The problem is that I didn't found a solution while googling all over the internet.

问题是我在网上搜索的时候没有找到解决办法。

Here is my setup.py

这是我的setup . py

from distutils.core import setup
import matplotlib
import py2exe 
matplotlib.use('TkAgg')
setup(data_files=matplotlib.get_py2exe_datafiles(),console=['run.py'])

3 个解决方案

#1


5  

First, the easy question, is that backend installed? On my Fedora system I had to install it separately from the base matplotlib.

首先,简单的问题是后端是否已安装?在我的Fedora系统上,我必须将它与基本的matplotlib分开安装。

At a Python console can you:

在Python控制台,您可以:

>>> import matplotlib.backends.backend_tkagg

If that works, then force py2exe to include it. In your config:

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

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

#2


2  

If you are using py2exe it doesn't handle .egg formatted Python modules. If you used easy_install to install the trouble module then you might only have the .egg version. See the py2exe site for more info on how to fix it.

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

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

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

#3


0  

This works well

这工作得很好

from distutils.core import setup import py2exe, sys, os import matplotlib

distutils。核心导入设置导入py2exe, sys, os导入matplotlib

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

sys.setrecursionlimit(12000)sys.argv.append(“py2exe”)

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

设置(选项= {"py2exe": {"bundle_files":3, "已压缩":True, "includes": ["matplotlib.backends。backend_tkagg "]} },windows =[{“脚本”:“script.py”}),

zipfile = None,

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

data_files=matplotlib data_files=matplotlib .get_py2exe_datafiles(),

#1


5  

First, the easy question, is that backend installed? On my Fedora system I had to install it separately from the base matplotlib.

首先,简单的问题是后端是否已安装?在我的Fedora系统上,我必须将它与基本的matplotlib分开安装。

At a Python console can you:

在Python控制台,您可以:

>>> import matplotlib.backends.backend_tkagg

If that works, then force py2exe to include it. In your config:

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

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

#2


2  

If you are using py2exe it doesn't handle .egg formatted Python modules. If you used easy_install to install the trouble module then you might only have the .egg version. See the py2exe site for more info on how to fix it.

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

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

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

#3


0  

This works well

这工作得很好

from distutils.core import setup import py2exe, sys, os import matplotlib

distutils。核心导入设置导入py2exe, sys, os导入matplotlib

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

sys.setrecursionlimit(12000)sys.argv.append(“py2exe”)

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

设置(选项= {"py2exe": {"bundle_files":3, "已压缩":True, "includes": ["matplotlib.backends。backend_tkagg "]} },windows =[{“脚本”:“script.py”}),

zipfile = None,

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

data_files=matplotlib data_files=matplotlib .get_py2exe_datafiles(),