I am using Python 3.5 within a program called OpenQuake. When I execute the following line, I get an import error "No module name 'tkinter'".
import matplotlib.pyplot as plt
I installed jupyter and executed the same and it works fine. Following is a snapshot.
I rechecked using IPython (which I believe comes with jupyter) to get exactly the same original error with the same traceback. Following is the traceback.
Traceback (most recent call last):
File "<ipython-input-22-964337a9f103>", line 2, in <module>
import matplotlib.pyplot as plt
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 6, in <module>
from matplotlib.externals.six.moves import tkinter as Tk
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 90, in __get__
result = self._resolve()
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 113, in _resolve
return _import_module(self.mod)
File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 80, in _import_module
__import__(name)
ImportError: No module named 'tkinter'
The matplotlib module that is referenced is the same in both the cases.
To summarize:
- The above code snippet gives an import error when using Python and IPython.
- The code snippet executes successfully in Jupyter.
Could someone explain why this is happening?