13

I am new to python and I am working on a graph problem and I want to draw this graph to have a better understanding of it. I learnt that matplotlib module is supposed to be imported for this but I dont know how to add it to the project.(I am a java developer and It is pretty much like adding jar to your classpath)

When I try doing

import matplotlib

I get the following error:

File "/Library/Python/2.7/site-packages/networkx-1.7rc1-py2.7.egg/networkx/drawing/nx‌​_pylab.py", line 114, in draw
    raise ImportError("Matplotlib required for draw()")
ImportError: Matplotlib required for draw()
ImportError: No module named matplotlib.pyplot

Can anyone help me with that?Do I need to download anything to make it run as in the module?

4
  • 1
    I recommend you to take a look in the source code of examples Commented Aug 5, 2012 at 10:13
  • 1
    Please follow the user guide Commented Aug 5, 2012 at 10:13
  • Windows, Linux, OSX? What is the name of your python file? You must help people to reproduce your error, otherwise nobody can help you. Commented Aug 5, 2012 at 14:43
  • 1
    have you download and installed matplotlib? Commented Aug 5, 2012 at 16:11

4 Answers 4

20

module: new

As David Robinson points out in a comment on another answer you may have posted an incomplete error message, in which case it is possible that the inbuilt module new is being shadowed by new.py in the gis module. - if that is the case the suggested fix is to rename the gis version.

Incomplete Matplotlib install

Alternatively, given your output you may be trying to import networkx and you don't seem to have matplotlib (correctly) installed.

Could you make sure that matplotlib is correctly installed, either if you're on Ubuntu by using

sudo apt-get install python-matplotlib

or if you prefer pip or easy_install,

pip install matplotlib

or

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

1 Comment

The pip command helped on Windows, since it is available after installing Python.
5

If you use windows, Open the command prompt and type

python -m pip install matplotlib

For linux users , type this

sudo apt-get install python-matplotlib

Comments

4

I had the same problem solved - not only for this package - using instead of pip install :

sudo apt-get install python-matplotlib

Comments

0

work on the cv virtual environment and then use the command and execute your script in the virtual environment using source ~/.profile workon cv

Comments

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.