我在Windows更新后使用matplotlib时遇到问题。我正在运行Windows 7 Service Pack 1 32位,我安装了Python和matplotlib作为Python(x,y)-2.7.6.1的一部分。问题似乎与FreeType有关,因为导入在ft2font上失败,如下面的堆栈跟踪所示:
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.
我尝试重新安装Python(x,y),但这并没有解决问题。
从Stackoverflow上的其他答案我了解到,此处的常见故障包括缺少msvcr90.dll
和msvcp90.dll
个文件。我下载了Dependency Walker并打开了c:\Python27\Lib\site-packages\matplotlib\FT2FONT.PYD
。这显示了这些文件和libbz2.dll
的问题。我下载并将这些文件复制到c:\windows\system32
。
我也尝试检查我的PATH
和PYTHONPATH
环境变量,但它们似乎正确引用了我的Python安装:
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
即使只使用上面会话中显示的Agg后端,问题也会出现,所以我不认为它与Qt或tk有任何关系。
答案 0 :(得分:5)
问题似乎是由应用程序在C:\Windows\System32\libbz2.dll
中安装不同/不兼容的BZ2版本引起的。这被用来代替Python(x,y)安装的Python27目录中的同名DLL。这就是Dependency Walker中出现的情况:
您可以看到libbz2.dll
出现问题,即使Dependency Walker没有将其列为依赖性错误。重命名或删除C:\Windows\System32\
中的版本会导致依赖关系由c:\Python27\DLLs
中的版本解析。