错误描述
当import matplotlib.pyplot
时可能出现以下错误:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/pyplot.py", line 37, in <module>
from matplotlib.figure import Figure, figaspect
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/figure.py", line 40, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/axes/__init__.py", line 4, in <module>
from ._subplots import *
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 24, in <module>
import matplotlib.dates as _ # <-registers a date unit converter
File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/dates.py", line 125, in <module>
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
File "/Users/brown/anaconda/lib/python3.6/site-packages/dateutil/rrule.py", line 55
raise ValueError, "Can't create weekday with n == 0"
^
SyntaxError: invalid syntax
错误分析解决
来自datautil
模块的文件rrule.py
使用了旧的语法,所以报异常。检查你安装的datautil
模块版本是否<= 1.5.x
,如果是的话,请使用以下命令升级此模块:
pip install python-dateutil --upgrade
Ref
http://stackoverflow.com/questions/32079919/trouble-with-importing-matplotlib