安装pyparsing,dateuil,six和numpy之后无法导入matplotlib

时间:2016-05-11 13:29:06

标签: python matplotlib

作为标题,我无法导入matplotlib ...

以下是代码:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('picture.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
magnitude_spectrum = 20*np.log(np.abs(fshift))

plt.subplot(121),plt.imshow(img, cmap = 'gray')
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray')
plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
plt.show()

以下是错误消息:

Traceback (most recent call last):


   File "<pyshell#4>", line 1, in <module>
   from matplotlib import pyplot as plt

   File "C:\Python34\lib\site-packages\matplotlib\__init__.py", line
138, in <module>

import pyparsing

   File "C:\Python34\lib\site-packages\pyparsing.py", line 3478, in
<module>

    _escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])

   File "C:\Python34\lib\site-packages\pyparsing.py", line 948, in
setParseAction

    self.parseAction = list(map(_trim_arity, list(fns)))

   File "C:\Python34\lib\site-packages\pyparsing.py", line 808, in
_trim_arity
    this_line = extract_stack()[-1]

   File "C:\Python34\lib\site-packages\pyparsing.py", line 793, in
extract_stack

    return [(frame_summary.filename, frame_summary.lineno)]

 AttributeError: 'tuple' object has no attribute 'filename'

提前致谢!

3 个答案:

答案 0 :(得分:2)

这是一个pyparsing问题:

https://github.com/matplotlib/matplotlib/issues/6399

等待修复。或者你可以将python升级到3.5

答案 1 :(得分:2)

由于最近版本的pyparsingmatplotlib发生冲突而导致错误,该点数已经提升。

解决方法是:pip install pyparsing==2.1.1后跟pip install matplotlib

答案 2 :(得分:2)

我安装了最新的pyparsing(2.1.3)并解决了这个问题!

下载页面:https://pypi.python.org/pypi/pyparsing/2.1.3