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]
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.
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
For python3. Just need to run pip3 install matplotlib
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!
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
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