简体   繁体   English

Python3.5 backend_tkagg 不再可用?

[英]Python3.5 backend_tkagg no longer available?

I'm trying to run an application that was running before.我正在尝试运行之前运行的应用程序。 It used to run on both Ubuntu and Windows 7. I now have a Windows 10 machine, and the code fails.它曾经在 Ubuntu 和 Windows 7 上运行。我现在有一台 Windows 10 机器,但代码失败了。 It might be because I'm on python 3.5 now, though I frankly can't remember what I was on on the other machines (which are no longer available).这可能是因为我现在使用的是 python 3.5,但坦率地说,我不记得我在其他机器(不再可用)上使用了什么。

The key lines are:关键行是:

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

which has been lifted from various places some time ago.前段时间从各个地方解除了。 However, now when I run it, it throws an error:但是,现在当我运行它时,它会引发错误:

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.

In an interactive session, it seems that it's the third line that's failing:在交互式会话中,似乎是第三行失败了:

>>> 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.

I tried我试过

pip uninstall matplotlib
pip install matplotlib

in the command prompt, but the error remained.在命令提示符下,但错误仍然存​​在。

It seems there may be a python-matplotlib-tk package, but I'm not sure what this is.似乎有一个 python-matplotlib-tk 包,但我不确定这是什么。

Should I drop back to python 3.4, or is there a solution for this?我应该回到python 3.4,还是有解决方案? Is this a known problem?这是一个已知问题吗?


In response to the below comment on installing matplotlib:回应以下关于安装 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

I had the same problem我有同样的问题

I read the docs in matplotlib我阅读了matplotlib 中的文档

For Python 3.5 the Visual C++ Redistributable for Visual Studio 2015 needs to be installed.对于 Python 3.5,需要安装 Visual C++ Redistributable for Visual Studio 2015。 In case Python 2.7 to 3.4 are not installed for all users (not the default), the Microsoft Visual C++ 2008 ( 64 bit or 32 bit for Python 2.7 to 3.2) or Microsoft Visual C++ 2010 ( 64 bit or 32 bit for Python 3.3 and 3.4) redistributable packages need to be installed.如果没有为所有用户安装 Python 2.7 到 3.4(不是默认设置),Microsoft Visual C++ 2008(64 位或 32 位 Python 2.7 到 3.2)或 Microsoft Visual C++ 2010(64 位或 32 位 Python 3.3 和3.4) 需要安装可再发行包。

And I installed the Visual C++ Redistributable for Visual Studio 2015 It solved the problem为 Visual Studio 2015安装 了 Visual C++ Redistributable它解决了这个问题

For those who just recently ran into this problem, I found the redistributable solution to not work, as I had both 32bit and 64bit redistributables already installed.对于最近遇到这个问题的人,我发现可再发行解决方案不起作用,因为我已经安装了 32 位和 64 位可再发行软件。

The solution I found was to replace NavigationToolbar2TkAgg with NavigationToolbar2Tk.我找到的解决方案是用 NavigationToolbar2Tk 替换 NavigationToolbar2TkAgg。

I've also found a way to import the packages, using 'import matplotlib as mpl':我还找到了一种导入包的方法,使用“import matplotlib as mpl”:

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

This works fine for me, hopefully it works for others too (:这对我来说很好用,希望它也适用于其他人(:

This is your problem:这是你的问题:

ImportError: DLL load failed: The specified module could not be found.导入错误:DLL 加载失败:找不到指定的模块。

You could try opening _tkagg.pyd in a software like Dependency Walker and look for errors.您可以尝试在Dependency Walker等软件中打开 _tkagg.pyd 并查找错误。

It's also possible that _tkagg.pyd was built with an incompatible version of the Python you are using _tkagg.pyd 也可能是使用不兼容的 Python 版本构建的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM