导入matplotlib.pyplot作为plt时出现Pycharm错误

时间:2014-10-09 23:17:39

标签: python python-2.7 matplotlib

我在windows 8中使用pycharm for python。我已经安装了matplotlib包。 我正在使用python 2.7 当我导入matplotlib 时没有错误 但是,如果我将 matplotlib.pyplot作为plt ,我会收到以下错误:

        Traceback (most recent call last):
  File "C:/Users/PiyushSudip/PycharmProjects/myFirst/test1.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module>
    from matplotlib.figure import Figure, figaspect
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Python27\lib\site-packages\matplotlib\axes\__init__.py", line 4, in <module>
    from ._subplots import *
  File "C:\Python27\lib\site-packages\matplotlib\axes\_subplots.py", line 10, in <module>
    from matplotlib.axes._axes import Axes
  File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 18, in <module>
    from matplotlib.cbook import _string_to_bool, mplDeprecation
ImportError: cannot import name _string_to_bool

任何人都可以帮助弄清楚我做错了什么吗?

1 个答案:

答案 0 :(得分:3)

http://matplotlib.org/users/installing.html#required-dependencies

有一个名为six的包,matplotlib依赖它。检查以确保已安装,或从此处安装:http://www.lfd.uci.edu/~gohlke/pythonlibs/#six

这个网站有很多python模块的打包版本,很容易在windows上设置,只需下载和运行。

同时检查其他依赖项以确保您拥有所有依赖项,否则可能会因其他模块而出现其他错误