1

I am trying to import matplotlib like so:

import matplotlib.pyplot as plt

For this I have installed matplotlib using.

python -m pip install -U pip setuptools
python -m pip install matplotlib

Although the basic_example.py from the examples worked, it suddenly stopped running along with all other files with matplotlib giving me the below error:

File "matplotlib.py", line 2, in <module>
  import matplotlib.pyplot as plt # pyplot module.
ImportError: No module named pyplot`

I tried to check if the module is still there, and it seems to be. What could be possibly wrong?

Requirement already satisfied: matplotlib in c:\python27\lib\site-packages
Requirement already satisfied: numpy>=1.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: python-dateutil in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: cycler in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,>=1.5.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: six>=1.5 in c:\python27\lib\site-packages (from python-dateutil->matplotlib)`

I am using Windows and Python 2.7.

4
  • What happens when you run import matplotlib Commented Dec 19, 2016 at 23:44
  • Why's there a grave accent in ImportError: No module named pyplot` o_o Commented Dec 19, 2016 at 23:51
  • @TedPetrou same error. import matplotlib.pyplot as plt # pyplot module. ImportError: No module named pyplot Commented Dec 19, 2016 at 23:56
  • @moogle That grave accent seems to be just the result of someone's edit. Not related to the problem Commented Dec 19, 2016 at 23:58

1 Answer 1

5

Python 2.7 tries to find modules in the current working directory first, before going into the installed packages, so because you named your test file "matplotlib.py", it will interpret it as the matplotlib package. Rename your test file to something else, and it should be fine

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.