0

Can somebody help me with this problem?

  1. Python recognises matplotlib from the command line:

    import matplotlib
    matplotlib.__version__
    '3.4.3'
    
  2. But not from a script

    This is my script (to keep it simple):

    import matplotlib.pylab as plt
    import numpy as np
    

These are the errors:

Traceback (most recent call last):

  File "C:/Program Files/Python39/Scripts/matplotlib.py", line 1, in <module>

    import matplotlib.pylab as plt

  File "C:\Program Files/Python39/Scripts\matplotlib.py", line 1, in <module>

    import matplotlib.pylab as plt

ModuleNotFoundError: No module named 'matplotlib.pylab';
 
'matplotlib' is not a package
2
  • try this: import matplotlib.pyplot as plt Commented Sep 2, 2021 at 3:47
  • Your script is called matplotlib.py. You need to rename it Commented Sep 2, 2021 at 8:08

1 Answer 1

-1

Try Reinstalling the package or downgrading it to a more stable version like 2.02

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for taking the time to answer my question. :-) As it turns out renaming my file from matplotlib.py to plotting_with_mat.py worked like a charm.
Yes that also might be the problem as you cannot name a file the name of a package as it will not import correctly thus giving an error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.