Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib on Windows - dependency unresolved

I have had problems with using matplotlib after a Windows update. I'm running Windows 7 Service Pack 1 32 bit and I installed Python and matplotlib as part of Python(x,y)-2.7.6.1. The problem appears related to FreeType, as the import fails on ft2font as shown in the stack trace below:

In [1]: import matplotlib

In [2]: matplotlib.use('agg')

In [3]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt

C:\Python27\lib\site-packages\matplotlib\pyplot.py in <module>()
     22
     23 import matplotlib
---> 24 import matplotlib.colorbar
     25 from matplotlib import _pylab_helpers, interactive
     26 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike

C:\Python27\lib\site-packages\matplotlib\colorbar.py in <module>()
     27 import matplotlib.artist as martist
     28 import matplotlib.cbook as cbook
---> 29 import matplotlib.collections as collections
     30 import matplotlib.colors as colors
     31 import matplotlib.contour as contour

C:\Python27\lib\site-packages\matplotlib\collections.py in <module>()
     21 import matplotlib.artist as artist
     22 from matplotlib.artist import allow_rasterization
---> 23 import matplotlib.backend_bases as backend_bases
     24 import matplotlib.path as mpath
     25 from matplotlib import _path

C:\Python27\lib\site-packages\matplotlib\backend_bases.py in <module>()
     48
     49 import matplotlib.tight_bbox as tight_bbox
---> 50 import matplotlib.textpath as textpath
     51 from matplotlib.path import Path
     52 from matplotlib.cbook import mplDeprecation

C:\Python27\lib\site-packages\matplotlib\textpath.py in <module>()
      9 from matplotlib.path import Path
     10 from matplotlib import rcParams
---> 11 import matplotlib.font_manager as font_manager
     12 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     13 from matplotlib.ft2font import LOAD_TARGET_LIGHT

C:\Python27\lib\site-packages\matplotlib\font_manager.py in <module>()
     51 import matplotlib
     52 from matplotlib import afm
---> 53 from matplotlib import ft2font
     54 from matplotlib import rcParams, get_cachedir
     55 from matplotlib.cbook import is_string_like

ImportError: DLL load failed: The specified procedure could not be found.

I have tried reinstalling Python(x,y), but this did not resolve the problem.

From other answers on Stackoverflow I have learned that common failures here include missing msvcr90.dll and msvcp90.dll files. I downloaded Dependency Walker and opened c:\Python27\Lib\site-packages\matplotlib\FT2FONT.PYD. This showed issues with these files and with libbz2.dll. I downloaded and copied these files to c:\windows\system32.

I have also tried checking my PATH and PYTHONPATH environment variables, but they appear to reference my Python install correctly:

PATH: C:\Python27\Lib\site-packages\PyQt4;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Novell\GroupWise;C:\Program Files\MiKTeX 2.9\miktex\bin\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Common Files\AspenTech Shared\;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\gnuplot\binary;C:\Program Files\pythonxy\SciTE-3.3.2-3;C:\Program Files\pythonxy\console;C:\MinGW32-xy\bin;C:\Python27\Lib\site-packages\vtk
PYTHONPATH: c:\Python27\DLLs

The problem manifests even when only using the Agg backend as shown in the session above, so I don't think it has anything to do with Qt or tk.

like image 506
lip Avatar asked Oct 15 '14 13:10

lip


1 Answers

It appears that the problem was caused by an application installing a different/incompatible version of BZ2 in C:\Windows\System32\libbz2.dll. This was being used instead of the dll of the same name in the Python27 directory installed by Python(x,y). This is how the situation showed up in Dependency Walker:

Dependency Walker showing broken libbz2

You can see that there is something wrong with libbz2.dll even though Dependency Walker doesn't list it as a dependency error as such. Renaming or deleting the version in C:\Windows\System32\ caused the dependency to be resolved by the version in c:\Python27\DLLs.

like image 72
lip Avatar answered Oct 19 '22 00:10

lip