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. 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).
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.
Should I drop back to python 3.4, or is there a solution for this? Is this a known problem?
In response to the below comment on installing 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
For Python 3.5 the Visual C++ Redistributable for Visual Studio 2015 needs to be installed. 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.
And I installed the Visual C++ Redistributable for Visual Studio 2015 It solved the problem
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.
The solution I found was to replace NavigationToolbar2TkAgg with NavigationToolbar2Tk.
I've also found a way to import the packages, using '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.
You could try opening _tkagg.pyd in a software like Dependency Walker and look for errors.
It's also possible that _tkagg.pyd was built with an incompatible version of the Python you are using
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.