2

I've been attempting to install Matplotlib for a graphing project in Python. In accordance with recommendation from the Matplotlib website, I installed Anaconda as a pre-packaged python distributor. Anaconda seems to have installed correctly. To install matplotlib, I typed in the command line:

pip install matplotlib

Which brings up multiple messages stating: "Requirement already satisfied." When in my python script I typed:

import matplotlib.pyplot as plt

I received an error message stating:

ImportError: No module named matplotlib.pyplot

I'm using an old Windows XP operating system.

I've looked everywhere for help, and have tried installing matplotlib numerous times via the command line! Any help would be greatly appreciated... Thank you!!

Eragon20
  • 483
  • 1
  • 7
  • 20
  • 1
    what is the name of your python script? What happens if you try `import matplotlib.pyplot as plt` in the console? – categulario Jun 02 '16 at 02:44
  • The name of my script is graph_plot.py... When I plug that command into the console I get error messages referncing __init__.py in the matplotlib file itself. – Eragon20 Jun 02 '16 at 03:28

1 Answers1

2

Make sure your version of pip corresponds to your version of python. One way to do this is the following:

python -m pip install matplotlib

The -m for module means that it will look in the site-packages for that python for the pip module.

You can also do:

>>> import sys
>>> print("\n".join(sys.path))

to list the path as understood by python, then check whether matplotlib is indeed on one of the listed paths (usually site-packages).


To find the locations of pip and python use the following on the Windows console:

where python
where pip

From the path you should be able to determine whether pip and python are from the same package. If not, uninstall one of the python installations, or at least remove it from the PATH variable.

Neapolitan
  • 2,101
  • 9
  • 21
  • I tried your second option...Matplotlib is not listed! What should I do now? Thanks for the help! – Eragon20 Jun 02 '16 at 03:26
  • Assuming you looked at the site-package directory in the file explorer and saw that there was no matplotlib in that directory, then you probably have two versions of python on your system, one which pip is using and another which you are using to start your python interpreter. IIRC, the command `where pip` in the windows cmd console will tell you the path to pip and `where python` will tell you the path to python. – Neapolitan Jun 02 '16 at 03:32
  • Note: the first option installs matplotlib in the interpreter used by python, so you want to try that. And you want to remove the extra versions of python from your system to avoid this confusion. – Neapolitan Jun 02 '16 at 03:33
  • Alright, so now I only have one version of python on my computer...It's definitely the version with the Anaconda extension...My issue now is that when I attempt to import mathplotlib I get an error referncing line 52 of matplotlib.colors.py "import numpy as np." It claims that there is no module named numpy. I did not write this command, so is this some error with python itself? Again, I really appreciate your help... – Eragon20 Jun 02 '16 at 03:42
  • Thanks for all of your help!! In the end, I actually ended up reinstalling both Anaconda and Python, and now it works perfectly!! – Eragon20 Jun 02 '16 at 05:45