1
votes

Brand new to Python (typically program in MSDN C#) and I'm trying to make use of the matplotlib to generate some graphics from .csv files

I've downloaded & installed Python as well as Anaconda onto my Windows 10 machine, the versions are Python 3.5.2 and Anaconda 4.1.1

I open up the Python "notepad" interface and do

import matplotlib.pyplot as plt

plt.plot([1,2,3],[3,2,1])

plt.show()

but when I run the code I get the error:

ImportError: No module named 'matplotlib'

I've looked at some other posts for this but they all seem to be in regard to Mac OSX or Linux. Some have pointed to multiple installs of matplotlib, but I haven't turned up such a situation so far. What might be causing this, or how can I troubleshoot it?

**Edit:

The path returned to me from the import sys recommended in the comments gave me this response

['C:\Users\a.watts.ISAM-NA\Desktop',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python35.zip',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\DLLs',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages',

'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages\setuptools-26.1.1-py3.5.egg']

1
Try this command: conda install matplotlib.Peter234
Where is your matplotlib install directory? Is it that directory in your path? (You can check your path in Python by using import sys and print(sys.path).)Samira N
If matplotlib is in AppData\local\continuum... and your python path doesn't contain that, then you might have a problem indeed.Andras Deak
@AlexWatts When you try to import a module in Python, the interpreter will search the directories listed in sys.path for a module with that name. If your matplotlib install directory isn't in sys.path, then it won't be able to find matplotlib. I'd recommend copying matplotlib from its current install location and moving it to C:\...\Python\Python35-32\lib\site-packages.Samira N
Anaconda ships with a python.exe for the version you downloaded. The Anaconda version of the IDLE is called spyder so if you run the code in your question in that I think it should workMr.F

1 Answers

3
votes

You essentially have 2 versions of python on your system - the standard one you downloaded and the one that ships with Anaconda. When you are running code in the IDLE you are using the standard version (in C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python.exe) where matplotlib isn't installed which is why you are getting the error.

You need to use the Anaconda version (C:\Users\a.watts.ISAM-NA\AppData\Local\continuum\anaconda3\python.exe) that comes with the scientific stuff already setup. It looks like your system is using this one from the cmd so if you run scripts from there it should use the Anaconda version. If you want to use something more interactive you can also use spyder - the Anaconda version of the IDLE - or run jupyter notebook from cmd to get a browser based platform for interactive development