[Python] Matplotlib invalid syntax (__init__.py, line 3) when importing matplotlib as mpl

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I installed matplotlib using pip install matplotlib, and I'm trying to import it but when I run my script I'm getting a syntax error in the __init__.py (line 3). Here's my code and the error I'm getting. I'm running python 3.10.4 and matplotlib 3.5.3.

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import numpy as np


    Exception has occurred: SyntaxError
    invalid syntax (__init__.py, line 3)
    File "C:\path\to\my\script.py", line 1, in <module>
    import matplotlib as mpl


    First few lines of __init__.py of matplotlib are:

    """
    An object-oriented plotting library.

    A procedural interface is provided by the companion pyplot module,
    which may be imported directly, e.g.::

    Continue reading...

Compartilhe esta Página