import matplotlib.pyplot 错误

错误描述

import matplotlib.pyplot时可能出现以下错误:

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/pyplot.py", line 37, in 
    from matplotlib.figure import Figure, figaspect
  File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/figure.py", line 40, in 
    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 
    from ._subplots import *
  File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/axes/_subplots.py", line 10, in 
    from matplotlib.axes._axes import Axes
  File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 24, in 
    import matplotlib.dates as _  # <-registers a date unit converter
  File "/Users/brown/anaconda/lib/python3.6/site-packages/matplotlib/dates.py", line 125, in 
    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

你可能感兴趣的:(python)