简体   繁体   中英

ImportError: No module named 'matplotlib'

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']

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM