Python3.5 backend_tkagg不再可用?

时间:2016-03-04 20:52:01

标签: python matplotlib tkinter

我试图运行之前运行的应用程序。它曾经在Ubuntu和Windows 7上运行。我现在有一台Windows 10机器,代码失败了。可能是因为我现在在python 3.5上,虽然我坦率地记不起我在其他机器上的内容(不再可用)。

关键是:

import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
前一段时间从各个地方被解除了。但是,现在当我运行它时,它会抛出一个错误:

Traceback (most recent call last):
  File "C:\....py", line 17, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
  File "C:\Users\...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 13, in <module>
    import matplotlib.backends.tkagg as tkagg
  File "C:\Users\g...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\tkagg.py", line 9, in <module>
    from matplotlib.backends import _tkagg
ImportError: DLL load failed: The specified module could not be found.

在互动环节中,似乎第三条线路失败了:

>>> import matplotlib
>>> matplotlib.use("TkAgg")
>>> from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
  File "C:\Users\...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 13, in <module>
    import matplotlib.backends.tkagg as tkagg
  File "C:\Users\...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\backends\tkagg.py", line 9, in <module>
    from matplotlib.backends import _tkagg
ImportError: DLL load failed: The specified module could not be found.

我试过

pip uninstall matplotlib
pip install matplotlib

在命令提示符下,但错误仍然存​​在。

似乎可能有一个python-matplotlib-tk包,但我不确定这是什么。

我应该回到python 3.4,还是有解决方案?这是一个已知的问题吗?

回应以下关于安装matplotlib的评论:

C:\>pip install matplotlib
Collecting matplotlib
  Downloading matplotlib-1.5.1-cp35-none-win32.whl (6.2MB)
    100% |################################| 6.2MB 67kB/s
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pytz in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): cycler in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.4,>=1.5.6 in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\users\...\appdata\local\programs\python\python35-32\lib\site-packages (from python-dateutil->matplotlib)
Installing collected packages: matplotlib
Successfully installed matplotlib-1.5.1

4 个答案:

答案 0 :(得分:4)

我遇到了同样的问题

我在matplotlib

中阅读了文档
  

对于Python 3.5 Visual Studio 2015的Visual C ++ Redistributable   需要安装。如果没有安装Python 2.7到3.4   所有用户(不是默认用户),Microsoft Visual C ++ 2008(64位或   32位用于Python 2.7到3.2)或Microsoft Visual C ++ 2010(64位或   Python 3.3和3.4的32位需要可再发行的软件包   安装。

我安装了the Visual C++ Redistributable for Visual Studio 2015 它解决了这个问题

答案 1 :(得分:1)

我还found使用'import matplotlib as mpl'导入包的方法:

       import matplotlib as mpl
       mpl.use("TkAgg")
       from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

这对我来说很好,希望它也适用于其他人(:

答案 2 :(得分:0)

这是你的问题:

ImportError:DLL加载失败:找不到指定的模块。

您可以尝试在Dependency Walker等软件中打开_tkagg.pyd并查找错误。

_tkagg.pyd也可能是使用您正在使用的Python的不兼容版本构建的

答案 3 :(得分:0)

对于刚遇到此问题的用户,我发现可再分发解决方案不起作用,因为我已经安装了32位和64位可再分发工具。

我找到的解决方案是将NavigationToolbar2TkAgg替换为NavigationToolbar2Tk。