Importing modules through the Python interpreter

If you are importing any module, then the Python interpreter checks if that module is available or not. You can do this by using the import statement. If that module is available, then you will see the >>> prefix after pressing the Enter key. This indicates that the execution was successful. If that module doesn't exist, the Python interpreter will show an error:

>>> import time
>>>

After importing the time module, we get the >>> prefix. This means that the module exists and this command gets executed successfully:

>>> import matplotlib

If the module doesn't exist, then you will get Traceback error:

File "<stdin>", line 1, in <module>
ImportError: No module named 'matplotlib'

So here, matplotlib isn't available, so it gives an error: ImportError: No module named 'matplotlib'.

To solve this error, we will have to install matplotlib and then again try to import matplotlib. After installing matplotlib, you should be able to import the module, as follows:

>>> import matplotlib
>>>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset