[Python] Error when "import matplotlib.pyplot as plt"

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I did not have any problem to use "plt", but it suddenly shows an error message and does not work, when I import it. Please see the below.

    >>> import matplotlib
    >>> import matplotlib.pyplot as plt


    Output:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 6, in <module>
    from matplotlib.figure import Figure, figaspect
    File "/usr/lib64/python2.6/site-packages/matplotlib/figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
    File "/usr/lib64/python2.6/site-packages/matplotlib/axes.py", line 2, in <module>
    import math, sys, warnings, datetime, new
    File "new.py", line 12, in <module>
    import matplotlib.pyplot as plt
    AttributeError: 'module' object has no attribute 'pyplot'


    This package is suddenly corrupted. So, I tried to install as below. I use Ubuntu.

    In [1]: sudo apt-get install python-matplotlib
    File "<ipython-input-1-2400ac877ebd>", line 1
    sudo apt-get install python-matplotlib
    ^
    SyntaxError: invalid syntax


    If I need to reinstall, what are the detailed instructions on how to do it?

    I am very new to Python. So, my problem might be too simple to be solved. But I cannot.

    Continue reading...

Compartilhe esta Página