ImportError: No module named matplotlib.pyplot

后端 未结 13 773
春和景丽
春和景丽 2020-11-28 02:03

I am currently practicing matplotlib. This is the first example I practice.

#!/usr/bin/python

import matplotlib.pyplot as plt

radius = [1.0, 2.0, 3.0, 4.0]         


        
相关标签:
13条回答
  • 2020-11-28 02:56

    You have two pythons installed on your machine, one is the standard python that comes with Mac OSX and the second is the one you installed with ports (this is the one that has matplotlib installed in its library, the one that comes with macosx does not).

    /usr/bin/python
    

    Is the standard mac python and since it doesn't have matplotlib you should always start your script with the one installed with ports.

    If python your_script.py works then change the #! to:

    #!/usr/bin/env python
    

    Or put the full path to the python interpreter that has the matplotlib installed in its library.

    0 讨论(0)
  • 2020-11-28 02:57

    I had a similar problem, using pip3 and all these things worked for installing matplotlib but not pyplot. This solved it for me:

    import matplotlib as plt
    from matplotlib import pyplot as pllt
    
    0 讨论(0)
  • 2020-11-28 02:58

    For python3. Just need to run pip3 install matplotlib

    0 讨论(0)
  • 2020-11-28 02:58

    I had a similar issue that I resolved and here is my issue:

    I set everything up on python3 but I was using python to call my file for example: I was typing "python mnist.py" ...since I have everything on python3 it was thinking I was trying to use python 2.7

    The correction: "python3 mnist.py" - the 3 made all the difference

    I'm by no means an expert in python or pip, but there is definitely a difference between pip and pip3 (pip is tied to python 2.7) (pip3 is tied to python 3.6)

    so when installing for 2.7 do: pip install when installing for 3.6 do: pip3 install

    and when running your code for 2.7 do: python when running your code for 3.6 do: python3

    I hope this helps someone!

    0 讨论(0)
  • 2020-11-28 03:04

    This worked for me, inspired by Sheetal Kaul

    pip uninstall matplotlib
    python3 -m pip install matplotlib
    

    I knew it installed in the wrong place when this worked:

    python2.7
    import matplotlib
    
    0 讨论(0)
  • 2020-11-28 03:05

    If you are using Python 2, just run

    sudo apt-get install python-matplotlib
    

    The best way to get matplotlib is :

    pip install matplotlib
    

    cause the previous way may give you a old version of matplotlib

    0 讨论(0)
提交回复
热议问题