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!!

2
  • 1
    what is the name of your python script? What happens if you try import matplotlib.pyplot as plt in the console? Commented Jun 2, 2016 at 2: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. Commented Jun 2, 2016 at 3:28

1 Answer 1

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.

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

5 Comments

I tried your second option...Matplotlib is not listed! What should I do now? Thanks for the help!
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.
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.
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...
Thanks for all of your help!! In the end, I actually ended up reinstalling both Anaconda and Python, and now it works perfectly!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.