Skip to main content
 首页 » 编程设计

Python之matplotlib 雨滴示例中的导入错误

2024年10月24日13jirigala

我正在尝试运行 Nicolas Rougier's raindrop animation在我的 Python 2.7.10 IDLE(在 Mac、OS X 10.10.5 上运行)上使用 matplotlib(版本 1.4.3),但出现以下导入错误:

Traceback (most recent call last): 
  File "<pyshell#1>", line 1, in <module> 
.... 
    from matplotlib import pyplot as plt 
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 34, in <module> 
    from matplotlib.figure import Figure, figaspect 
  File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 40, in <module> 
    from matplotlib.axes import Axes, SubplotBase, subplot_class_factory 
  File "/Library/Python/2.7/site-packages/matplotlib/axes/__init__.py", line 4, in <module> 
    from ._subplots import * 
  File "/Library/Python/2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in <module> 
    from matplotlib.axes._axes import Axes 
  File "/Library/Python/2.7/site-packages/matplotlib/axes/_axes.py", line 21, in <module> 
    import matplotlib.dates as _  # <-registers a date unit converter 
  File "/Library/Python/2.7/site-packages/matplotlib/dates.py", line 126, in <module> 
    from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, 
  File "/Library/Python/2.7/site-packages/dateutil/rrule.py", line 16, in <module> 
    from six.moves import _thread 
ImportError: cannot import name _thread 

我使用的脚本与链接中的脚本完全相同,但我必须在之前插入语句 import matplotlib 和 matplotlib.use('TKAgg') pyplot 和 FuncAnimation 在顶部导入语句。

请您参考如下方法:

您需要重新安装 python 的 dateutil 包。

sudo pip uninstall dateutil 
sudo pip install python-dateutil==2.2